How to use the ASP.NET DropDownList control

  • 2020-05-09 18:26:59
  • OfStack

1. Data binding

 
this.DropDownList1.DataSource = CategoryManager.getCategories(); 
DropDownList1.DataValueField = "id";// Used to set the drop-down list selection  Value  value  
DropDownList1.DataTextField = "name";// The value displayed for the drop-down list option  
DropDownList1.DataBind(); 


2. Read data
 
int categoryId = int.Parse(this.DropDownList1.SelectedItem.Value);// Gets the selected value in the drop-down list  

Related articles: