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

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

    Sub Page_Load()

    Dim strConnection As New

    Dim families As string = "SELECT family_Name FROM

    Dim DS1 As DataSet
    Dim CommandFamilies As SqlDataAdapter

    CommandFamilies = New SqlDataAdapter(families, strConnection)

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


    End Sub



    <form runat="server">

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


    cesark, Jan 20, 2004
    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
    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
    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.