htm11h
htm11h

Reputation: 1779

correct syntax for if statement to check dbnull inline asp

I am looking for some help on the syntax to check for DBNull inline in asp...

<EditItemTemplate>
  <asp:CheckBox ID="Checkbox1" runat="server" Checked='<%# If(isDBNull(Eval("activeType")).Value, False, Convert.ToBoolean(Eval("activeType"))) %>'></asp:CheckBox>
 </EditItemTemplate>

Hoping someone can show me the light on this one..

Thanks,

Upvotes: 0

Views: 2052

Answers (1)

Scott Selby
Scott Selby

Reputation: 9580

you had it fine , just take out .Value , isDBNull(Eval("activeType")) this will work , you can not get the Value of dbNull , so the exception is thrown before it actually gets to check if it's null

<EditItemTemplate>
<asp:CheckBox ID="Checkbox1" runat="server" Checked='<%# If(isDBNull(Eval("activeType")), False, Convert.ToBoolean(Eval("activeType"))) %>'></asp:CheckBox>
</EditItemTemplate>

Upvotes: 2

Related Questions