Hi,

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.

Like this:

HTML

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

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));
    }