Click here to Skip to main content
14,392,596 members
Rate this:
Please Sign up or sign in to vote.
See more:
view dropdownlist corrosponding value in anther drpdownlist



hi all,

i am using one dropdownlist for showing EmpNO from DB
i want when i select dropdown value it should be display corresponing value
in another dropdownlist.but don't know how to do this.tell me what is c# code for this.
Posted
Updated 26-Sep-12 18:24pm
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

protected void ddlemployeeno_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddlemployeename.Items.Clear();
        //Fetch the records for all the employeename & employeeno  in dataset
        DataRow[] drEmployeeName = dsemployeeno.Tables[0].Select("EmployeeNo='" + ddlemployeeno.SelectedValue.ToString() + "'");
        foreach (DataRow drrow in drEmployeeName)
        {
            ddlemployeename.Items.Add(new ListItem(drrow["name_of_column"].ToString(), drrow["name_of_column"].ToString()));
        }
        ddlemployeename.Items.Insert(0,new ListItem("-Select-"));

    }
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

// Firstly u should get selected value of first dropdown


protected void ddlStateCode_SelectedIndexChanged(object sender, EventArgs e)
    {
              string  strStateCode ="";
              strStateCode = ddl1.SelectedValue;
             // now u should send this value to database and get records according to this value and bind second dropdown with record 
            DataSet dsCity= new DataSet();
            dsCity= obj.fnGetDetails("strStateCode");// Get city details according to state code
            ddlCity.DataSource = dsCity.Tables[1];
            ddlCity.DataValueField = "Code";
            ddlCity.DataTextField = "Description";

            ddlCity.DataBind();
            ddlCity.Items.Insert(0, new ListItem("---Select City---", "0"));
  
                      
     }

Thanks
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

Hi
select auto post back = true for both the dropdownlist.

In dropdownlist1 selectedindexchange event put this code

DropDownList2.SelectedValue = DropDownList1.SelectedValue;

Happy coding....
   
Rate this:
Please Sign up or sign in to vote.

Solution 5

write this code

dropdownlist1selectionchanged_Event

dropdownlist2.text=dropdownlist1.text;


Regard
Sham:)
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100