I have a dropdownlist named MyDropDown. I have declared an arraylist and I collect required names of collection in the list. In parallel, I would like to keep appending the names obtained in dropdownlist.

I have an If condition, checking for proper valid names. Those names I wish to display in dropdownlist.

I tried all the properties/events/methods and combinations of the dropdownlist, but could not obtain desired result.

The value of valid name is stored in a string variable ie

string name = MyString.title;

and immediately after this, I need to insert this value in MyDropDown so that it goes into for each for new value again. and new value will be inserted in MyDropDown below the previous one.

Please help !! M stuck on it since 3 days.. Did a lot of trial and error.. Your help would be highyl appreciated.

4 Years
Discussion Span
Last Post by ggamble

Like this:


    <form id="form1" runat="server">
    <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True">
    <br />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <br />
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

Code Behind:

    protected void Button1_Click(object sender, EventArgs e)
        string sText = TextBox1.Text;
        TextBox1.Text = string.Empty;
        DropDownList1.Items.Add(new ListItem(sText,sText));
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.