Null values in a datagrid checkbox column

R

Rock

I have a checkbox column in a bound datagrid that returns an error when it
hits a null value: [FormatException: Input string was not in a correct
format.]

I can't modify the sql query to anticipate a null value, how can I do this
programmatically or in html code? Such as in the ItemDataBound even of the
datagrid?? Thanks for any help.


<asp:TemplateColumn HeaderText="Validated">
<ItemTemplate>
<asp:checkbox id=chk1 runat="server" Checked='<%#
DataBinder.Eval(Container.DataItem,"Validated") %>'>
</asp:checkbox>
</ItemTemplate>
</asp:TemplateColumn>
 
K

Ken Cox [Microsoft MVP]

Hi,

One way is to use a helper function. Pass the (possibly) null value into it,
test for dbnull and return a boolean. Some code below.

Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto

Function fixnull(ByVal blnIn As Object) _
As Boolean
If IsDBNull(blnIn) Then
Return False
End If
Return CType(blnIn, Boolean)
End Function

<asp:templatecolumn HeaderText="Validated">
<itemtemplate>
<asp:checkbox id="chk1" runat="server"
Checked='<%# fixnull( DataBinder.Eval(Container.DataItem,"Validated") )%>'>
</asp:checkbox>
</itemtemplate>
</asp:templatecolumn>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top