asp.net – ASP:ItemTemplate中的DropDownList:为什么允许SelectedValue属
发布时间:2021-01-12 09:35:05 所属栏目:asp.Net 来源:互联网
导读:这段代码 asp:DropDownList runat=server ID=testdropdown SelectedValue=2 asp:ListItem Text=1 Value=1/asp:ListItem asp:ListItem Text=2 Value=2/asp:ListItem asp:ListItem T
|
这段代码 <asp:DropDownList runat="server" ID="testdropdown" SelectedValue="2">
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
</asp:DropDownList>
产生此错误:
然而,这是一个合法且常用的数据绑定GridView的编辑模板. SelectedValue属性当然似乎在这里声明性地设置. <EditItemTemplate>
<asp:DropDownList runat="server"
ID="GenreDropDownList"
DataSourceID="GenreDataSource"
DataValueField="GenreId"
DataTextField="Name"
SelectedValue='<%# Bind("Genre.GenreId") %>'>
</asp:DropDownList>
</EditItemTemplate>
问题是:当你被允许声明性地设置它们和你不属性的情况之间有什么区别?错误信息意味着它不会被允许. 解决方法这意味着您无法通过设计器进行设置.正确的方法是: <asp:DropDownList runat="server" ID="testdropdown">
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2" Selected></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
</asp:DropDownList>
绑定方法的工作原因是因为在设计模式中未选择值,而是在控件绑定到数据源之后的运行时 DropDownList.SelectedValue方法意在在运行时应用,因此无法将其设置为“装饰性”的错误 (编辑:东莞站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – WebForm_DoCallback定义
- asp.net中让Repeater和GridView支持DataPager分页
- asp.net – 避免在web.config中提供服务器连接字符串
- asp.net webservice返回json的方法
- asp.net – 在为app_offline.htm提供特定URL时,将http状态5
- 将ASP.NET应用程序本地化为普通话
- asp.net文件上传功能(单文件,多文件,自定义生成缩略图,水印
- asp.net-mvc – .Net 4.5.1框架的maxRequestLength
- ASP.NET Core 1.0 ConfigurationBuilder().AddJsonFile(“a
- asp.net-mvc – 如何在RegularExpression中忽略大小写?
