Databound Dropdownlist - How say if null then 0

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!
 
Y

Yankee Imperialist Dog

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.
 
C

Cirene

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.
 

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

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top