Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
Hi
C#
if (!IsPostBack)
  {

        ddlTableType.ClearSelection();

        ddlTableType.Items.Add(new ListItem("-Select-", "Select"));
        ddlTableType.Items.Add(new ListItem("Test Script Components"));
        ddlTableType.Items.Add(new ListItem( "Test Scripts"));
        ddlTableType.Items.Add(new ListItem( "Batch Scripts"));
  }


}







protected void ddlTableType_SelectedIndexChanged(object sender, EventArgs e)
{

    List<string> lsItems = null;

    if (ddlTableType.SelectedIndex == 1)
    {
        lsItems = ems.getTestScriptComponentsList(con);


    }

    else if (ddlTableType.SelectedIndex == 2)
    {
        lsItems = ems.getTestScriptsList(con);


    }

I have the list of items in lsItems.. I wanted to display in the second dropdown list (ddlTableName) how do i get the list of items from (lsItems) and display it in ddlTableName
Posted

You just run it true a foreach loop.

C#
List<string> list = new List<string>();

            list.Add("one");
            list.Add("two");

            foreach (var item in list)
            {
                DropDownList1.Items.Add(item);
            }</string></string>
 
Share this answer
 
When the Event is trigered clear the dropdownlist before you populate it.

C#
List<string> lsItems = null;

            //Clear DropDownList
            DdlTableName.Items.clear()

        if (ddlTableType.SelectedIndex == 1)
        {
            lsItems = ems.getTestScriptComponentsList(con);

            
 
           // DataSet ds;

            //ds =lsItem

            foreach (var item in lsItems)
            {
                ddlTableName.Items.Add(item);
            }
 

 

        }
 
        else if (ddlTableType.SelectedIndex == 2)
        {
            lsItems = ems.getTestScriptsList(con);
 
            foreach (var item in lsItems)
            {
                ddlTableName.Items.Add(item);
            }
 
        }
 
Share this answer
 
v4
Thanks it works .. how do i clear the items when first drop dwon changes
 
Share this answer
 
Comments
Christopher Kenis 6-Sep-13 7:13am    
Mark it as a solution then :p

DropDownListFirstList.Items.Clear() if you want to delete all items in the DropDownList

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900