The first value of a dropdownlist

Discussion in 'ASP .Net' started by cesark, Jan 20, 2004.

  1. cesark

    cesark Guest

    How can I show a value at the beginning of the dropdownlist with my
    structure? This initial value isn' t in the database, for instance
    '(Select)'.



    <script language="VB" runat="server">

    Sub Page_Load()

    Dim strConnection As New
    SqlConnection("Server=nou;database=market1;uid=sa;password=;")

    Dim families As string = "SELECT family_Name FROM
    Families;"



    Dim DS1 As DataSet
    Dim CommandFamilies As SqlDataAdapter

    CommandFamilies = New SqlDataAdapter(families, strConnection)

    DS1 = new DataSet()
    CommandFamilies.Fill(DS1, "Families")


    MySelect1.DataSource=
    DS1.Tables("Families").DefaultView
    MySelect1.DataBind()



    End Sub

    </script>



    ....

    <form runat="server">

    <asp:dropdownlist id="MySelect1"
    DataTextField="family_Name" runat="server"
    class="letter1">

    </asp:dropdownlist>

    ....
     
    cesark, Jan 20, 2004
    #1
    1. Advertisements

  2. cesark

    George Durzi Guest

    not sure of the VB .net syntax, but here it is in C#

    ListItem li = new ListItem();
    YourDDL.Items.Add(li, 0);

    put's a blank item at the beginning of your drop down list

    =---
     
    George Durzi, Jan 21, 2004
    #2
    1. Advertisements

  3. cesark

    cesark Guest

    I have already achieved it 8) . The right code was:

    MySelect2.Items.Insert(0, "(Select a value)")
    MySelect2.SelectedIndex = 0

    Just before of 'MySelect2.DataBind()'

    Thank you anyway :)
     
    cesark, Jan 21, 2004
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.