dropdownlist initial value

Discussion in 'ASP .Net' started by DC Gringo, Mar 3, 2004.

  1. DC Gringo

    DC Gringo Guest

    I have a dropdownlist that is bound to a recordset. The default selected
    item has turned out to be the first record in my table. I need a row that
    has value = 0 and text showing "--ALL".

    How can I do this?

    <asp:dropdownlist id="Provinces" runat="server" Font-Size="8pt"
    Width="100px"></asp:dropdownlist>

    Sub BindData()

    Dim myDataSet5 As New DataSet
    Dim myDataAdapter5 As New SqlDataAdapter(_sqlStmt5, conString)
    myDataAdapter5.Fill(myDataSet5, "CommunitiesT2")
    ddlCommunities.DataSource = myDataSet5.Tables("CommunitiesT2")
    ddlCommunities.DataMember = "CommunitiesT2"
    ddlCommunities.DataTextField = "clnName"
    ddlCommunities.DataValueField = "clnGUID"
    ddlCommunities.DataBind()

    End Sub
    --
    _____
    DC G
    DC Gringo, Mar 3, 2004
    #1
    1. Advertising

  2. If I am not wrong you can use the DropDownList.Insert to add the ALL item at
    position 0. You can do it after databind()

    "DC Gringo" <> wrote in message
    news:...
    > I have a dropdownlist that is bound to a recordset. The default selected
    > item has turned out to be the first record in my table. I need a row that
    > has value = 0 and text showing "--ALL".
    >
    > How can I do this?
    >
    > <asp:dropdownlist id="Provinces" runat="server" Font-Size="8pt"
    > Width="100px"></asp:dropdownlist>
    >
    > Sub BindData()
    >
    > Dim myDataSet5 As New DataSet
    > Dim myDataAdapter5 As New SqlDataAdapter(_sqlStmt5, conString)
    > myDataAdapter5.Fill(myDataSet5, "CommunitiesT2")
    > ddlCommunities.DataSource = myDataSet5.Tables("CommunitiesT2")
    > ddlCommunities.DataMember = "CommunitiesT2"
    > ddlCommunities.DataTextField = "clnName"
    > ddlCommunities.DataValueField = "clnGUID"
    > ddlCommunities.DataBind()
    >
    > End Sub
    > --
    > _____
    > DC G
    >
    >
    Carlos Campos, Mar 3, 2004
    #2
    1. Advertising

  3. DC Gringo

    Teemu Keiski Guest

    After call to ddlCommunities.DataBind() do:

    ddlCommunities.Items.Insert(0,New ListItem("--ALL","0"))

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist


    "DC Gringo" <> wrote in message
    news:...
    I have a dropdownlist that is bound to a recordset. The default selected
    item has turned out to be the first record in my table. I need a row that
    has value = 0 and text showing "--ALL".

    How can I do this?

    <asp:dropdownlist id="Provinces" runat="server" Font-Size="8pt"
    Width="100px"></asp:dropdownlist>

    Sub BindData()

    Dim myDataSet5 As New DataSet
    Dim myDataAdapter5 As New SqlDataAdapter(_sqlStmt5, conString)
    myDataAdapter5.Fill(myDataSet5, "CommunitiesT2")
    ddlCommunities.DataSource = myDataSet5.Tables("CommunitiesT2")
    ddlCommunities.DataMember = "CommunitiesT2"
    ddlCommunities.DataTextField = "clnName"
    ddlCommunities.DataValueField = "clnGUID"
    ddlCommunities.DataBind()

    End Sub
    --
    _____
    DC G
    Teemu Keiski, Mar 3, 2004
    #3
  4. DC Gringo

    DC Gringo Guest

    THANKS



    "Teemu Keiski" <> wrote in message
    news:...
    > After call to ddlCommunities.DataBind() do:
    >
    > ddlCommunities.Items.Insert(0,New ListItem("--ALL","0"))
    >
    > --
    > Teemu Keiski
    > MCP, Microsoft MVP (ASP.NET), AspInsiders member
    > ASP.NET Forum Moderator, AspAlliance Columnist
    >
    >
    > "DC Gringo" <> wrote in message
    > news:...
    > I have a dropdownlist that is bound to a recordset. The default selected
    > item has turned out to be the first record in my table. I need a row that
    > has value = 0 and text showing "--ALL".
    >
    > How can I do this?
    >
    > <asp:dropdownlist id="Provinces" runat="server" Font-Size="8pt"
    > Width="100px"></asp:dropdownlist>
    >
    > Sub BindData()
    >
    > Dim myDataSet5 As New DataSet
    > Dim myDataAdapter5 As New SqlDataAdapter(_sqlStmt5, conString)
    > myDataAdapter5.Fill(myDataSet5, "CommunitiesT2")
    > ddlCommunities.DataSource = myDataSet5.Tables("CommunitiesT2")
    > ddlCommunities.DataMember = "CommunitiesT2"
    > ddlCommunities.DataTextField = "clnName"
    > ddlCommunities.DataValueField = "clnGUID"
    > ddlCommunities.DataBind()
    >
    > End Sub
    > --
    > _____
    > DC G
    >
    >
    >
    DC Gringo, Mar 3, 2004
    #4
    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. Marek Ponca

    Initial value on ports

    Marek Ponca, Aug 8, 2003, in forum: VHDL
    Replies:
    0
    Views:
    2,702
    Marek Ponca
    Aug 8, 2003
  2. Roger Planger

    Initial Value at start of process

    Roger Planger, Oct 5, 2004, in forum: VHDL
    Replies:
    4
    Views:
    4,627
    Pieter Hulshoff
    Oct 6, 2004
  3. Replies:
    3
    Views:
    977
  4. PGK
    Replies:
    1
    Views:
    514
  5. DC Gringo

    dropdownlist initial value

    DC Gringo, Mar 3, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    188
    Ken Cox [Microsoft MVP]
    Mar 4, 2004
Loading...

Share This Page