Drop Down List help please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ummaria
    New Member
    • Mar 2007
    • 16

    Drop Down List help please

    Hello

    I have a drop down list that retrieves data from a data base.
    Under that I have a textbox that I want to retrieve information also from the database depending on the previously selected item.

    For example, if i select "Computer" from the dropdown list, the textbox should display "PC".

    This is part of my graduation project and I really need help.
    Thanks :)
  • avkdsiva
    New Member
    • Mar 2007
    • 23

    #2
    public static void LoadCombo(DropD ownList cmb,string KeyCodeColumn,s tring KeyNameColumn,s tring TableName,DataS et ds)
    {
    cmb.Items.Clear ();
    foreach (DataRow dr in ds.Tables[TableName].Rows)
    {
    ListItem ls = new ListItem(dr[KeyNameColumn].ToString().Tri m());
    if (KeyCodeColumn != "")
    ls.Value = dr[KeyCodeColumn].ToString().Tri m();
    cmb.Items.Add(l s);
    }
    }

    Now, if you want to display the value of the selected item in the textbox1, you can show it using
    textbox1.text = cmb.SelectedVal ue;

    Comment

    • nmsreddi
      Contributor
      • Jul 2006
      • 366

      #3
      Hello

      If your data is limited and static then you can go for arraylist colletion other if

      you want the data to get from database then simply you can use auto postback

      property of the combobox and write the code in combo selected index changed

      event for each time bind that corresponding data to the textbox its not a problem


      Good luck

      Comment

      Working...