c# - Binding binary field to ASP.NET DataGrid Causes Error -
i have dataset 1 of it's fields named "reviewed".
this dataset popualted , below picture show it's data: 
now im trying show dataset inside datagrid :
<asp:templatecolumn headertext="reviewed" headerstyle-horizontalalign="center" headerstyle-wrap="true"> <itemstyle wrap="false" horizontalalign="center" /> <itemtemplate> <asp:checkbox checked='<%# databinder.eval(container.dataitem, "reviewed") %>' runat="server" id="label22" /> </itemtemplate> <edititemtemplate> <asp:checkbox id="textbox5" width="40" checked='<%# databinder.eval(container.dataitem, "reviewed") %>' runat="server" /> </edititemtemplate> </asp:templatecolumn> i following error:
exception details: system.invalidcastexception: cast type 'dbnull' type 'boolean' not valid.
what doing wrong? question dbnull comes from?
================================
update:
thanks nice answers. main point of confusion "stupid" xml visualizer wrongly showing reviewed field checked(as see in picture above). checked values in dataset , realized indeed dbnull.
it means of data coming database null. need check before assigning.you might want assign default value like.
iif((databinder.eval(container.dataitem, "reviewed") dbnull.value),false, databinder.eval(container.dataitem, "reviewed"))) you can create method checks both dbnull , null values , returns appropriate value. (it may have syntax error can correct)
<asp:checkbox id="textbox5" width="40" checked='<%# yourmethod(eval("reviewed")) %>' runat="server" />
Comments
Post a Comment