By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,967 Members | 1,625 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,967 IT Pros & Developers. It's quick & easy.

Databound Dropdownlist - How say if null then 0

P: n/a
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!
Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

--
Share The Knowledge. I need all the help I can get and so do you!
"Cirene" wrote:
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!
Jun 27 '08 #2

P: n/a
awesome thanks!

"Yankee Imperialist Dog" <Ya******************@discussions.microsoft.com>
wrote in message news:ED**********************************@microsof t.com...
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.

--
Share The Knowledge. I need all the help I can get and so do you!
"Cirene" wrote:
>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!

Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.