Dynamically populating a dropdown list in ASP.Net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shikha1234
    New Member
    • Mar 2008
    • 10

    Dynamically populating a dropdown list in ASP.Net

    Hi,

    I have two dropdowns.
    I want that the DDL2 gets populated based on the values in DDL1.
    How can I achieve that.

    This is the way I am populating DDL1

    string cmd = "Select * from abc ";
    SqlDataAdapter da = new SqlDataAdapter( cmd, connection);

    DataSet ds = new DataSet();
    da.Fill(ds);
    DropDownList1.D ataSource = ds;
    DropDownList1.D ataTextField = "Name";
    DropDownList1.D ataValueField = "Code";
    DropDownList1.D ataBind();
    DropDownList1.I tems.Insert(0, "--Select--");
  • kunal pawar
    Contributor
    • Oct 2007
    • 297

    #2
    right, just set property Autopostback=tu re for DDL1 and populate ur DDL2 in selected indexchanged event of DDL1.
    to get selected value of DDL1
    dropdown1.selec tedItem.value
    & for text
    dropdown1.selec tedItem.text

    Comment

    • Shikha1234
      New Member
      • Mar 2008
      • 10

      #3
      Originally posted by kunal pawar
      right, just set property Autopostback=tu re for DDL1 and populate ur DDL2 in selected indexchanged event of DDL1.
      to get selected value of DDL1
      dropdown1.selec tedItem.value
      & for text
      dropdown1.selec tedItem.text



      Hey thanks a ton!
      I could achieve this

      Comment

      Working...