开发者

DropDownList can't bind to DbNull

I have a DropDownList trying to bind to DbNull and it's not happy about it. I've seen advice about creating a ListItem wi开发者_JAVA百科th value=" " but this isn't working.

Any help would be much appreciated.


if you want to add default value to dropdwon list you can do it as below

 mydropdown.DataSource = getdata();
 mydropdown.DataBind();
 mydropdown.Items.Insert(0,new ListItem("N/A","N/A"));

Edit

if you know some values of the datasouce is null than y dont you filter out those value at database level and than bind soruce with the drop down. or make use of Isnull() in query and assing default value to null values.


It shouldn't work to bound DBNull while the other items are e.g. of type int. With a white space or empty string I got problems too. So best way would be to change your DBNull entry with a constant value, that would not appear in your database and have the same data type like the other entries, for example -1.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜