Databound Dropdownlist - How say if null then 0

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cirene

    Databound Dropdownlist - How say if null then 0

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

    <asp:DropDownLi st 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:DropDownLis t>

    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!


  • =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?=

    #2
    RE: Databound Dropdownlist - How say if null then 0

    set the first item to <asp:ListItem value="0"></asp:ListItem>
    or use isNull(@ddlpara mpassedin, 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:DropDownLi st 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:DropDownLis t>
    >
    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!
    >
    >
    >

    Comment

    • Cirene

      #3
      Re: Databound Dropdownlist - How say if null then 0

      awesome thanks!

      "Yankee Imperialist Dog" <YankeeImperial istDog@discussi ons.microsoft.c om>
      wrote in message news:ED6D2C27-F026-4510-B195-F928CE20F132@mi crosoft.com...
      set the first item to <asp:ListItem value="0"></asp:ListItem>
      or use isNull(@ddlpara mpassedin, 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:DropDownL ist 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:DropDownLis t>
      >>
      >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!
      >>
      >>
      >>

      Comment

      Working...