Databound Dropdownlist - How say if null then 0

  • Thread starter Thread starter Cirene
  • Start date Start date
C

Cirene

In my databound datagrid i have a databound dropdownlist, like this:

<asp:DropDownList ID="ddlAvail0" runat="server"
SelectedValue='<%# Bind("AvailMon") %>'>
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="1">Yes</asp:ListItem>
<asp:ListItem Value="0">No</asp:ListItem>
</asp:DropDownList>

I would really prefer to use a checkbox, but because it doesn't have a 3rd
state for null I'm stuck using a dropdownlist.

Anyway, when the user is going to INSERT a new person the ddl defaults to
the first item, which is null.

Is there anyway to save 0 to the database automatically if the first
listitem is selected? I didn't have to write any code yet - just using the
designer.

I hope this makes sense.

Thanks for your advice!
 
set the first item to <asp:ListItem value="0"></asp:ListItem>
or use isNull(@ddlparampassedin, 0) in your insert statement. Assuming you
are using sqlserver.
 
awesome thanks!

Yankee Imperialist Dog said:
set the first item to <asp:ListItem value="0"></asp:ListItem>
or use isNull(@ddlparampassedin, 0) in your insert statement. Assuming you
are using sqlserver.
 
Back
Top