Databound Dropdownlist - How say if null then 0

Discussion in 'ASP .Net' started by Cirene, Jun 6, 2008.

  1. Cirene

    Cirene Guest

    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!
    Cirene, Jun 6, 2008
    #1
    1. Advertising

  2. 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!
    >
    >
    >
    Yankee Imperialist Dog, Jun 6, 2008
    #2
    1. Advertising

  3. Cirene

    Cirene Guest

    awesome thanks!

    "Yankee Imperialist Dog" <>
    wrote in message news:...
    > 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!
    >>
    >>
    >>
    Cirene, Jun 6, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rodchar
    Replies:
    0
    Views:
    374
    rodchar
    Nov 26, 2007
  2. Manu
    Replies:
    0
    Views:
    157
  3. Lagrange
    Replies:
    1
    Views:
    541
    Lagrange
    Jan 17, 2009
  4. Replies:
    0
    Views:
    252
  5. Don Vaillancourt

    First "undefined" then null and now "null"

    Don Vaillancourt, Oct 27, 2004, in forum: Javascript
    Replies:
    13
    Views:
    198
    Thomas 'PointedEars' Lahn
    Dec 11, 2004
Loading...

Share This Page