Thursday, April 21, 2011

drop down list binding

I have a table which has an Id and a name field. I usually bind the name to the dropdownlist but I was told that any dml should be on the Id so how can I use the name in the dropdownlist and at the same time still use the Id?

From stackoverflow
  • You can set the dropdownlist's Text field to the name and the Value field to the ID.

  • A very similar question was just answered a little while ago - here

  • Use DataTextField and DataValueField when binding:

    ddlList.DataSource = thesource;
    ddlList.DataTextField = "Name";
    ddlList.DataValueField = "ID";
    ddlList.DataBind()
    

    Where ID and Name are fields in your data source.

0 comments:

Post a Comment