希望有人能回答这个问题。我要拔头发了!
我有一个默认值为“”的DropDownList
,用于从数据库捕获 NULL。
DropDownList
的“Value”字段是 varchar
。
这很好用。
但是,在保存记录时,该值将作为空字符串保留在数据库中。
稍后重新绑定(bind)该记录会引发 ArgumentOutOfRangeException
。
有什么推荐的解决方案吗?
我目前使用以下绑定(bind)方法:
<asp:DropDownList ID="DestinationDropDownList" runat="server"
DataSourceID="CountryDataSource" DataTextField="Name"
DataValueField="CountryRegionCode" SelectedValue='<%#Bind("DestinationCountryCode")%>'
AppendDataBoundItems="True">
<asp:ListItem Text="Select..." Value=""></asp:ListItem>
</asp:DropDownList>
最佳答案
发现问题:
数据库中的“国家/地区”值字段是固定长度,因此它尝试绑定(bind)到“ ”(3 个空格),而现有 ListItem
值只是“”。
我将默认的 ListItem 值更改为“ ”,现在它工作得很好。
关于c# - DropDownList 中的 ASP.NET Bind() - 字符串值与 Null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15917293/