ASP.NET ComboBox - Populating with Data - SqlDataSource



The ComboBox can be populated from various types of data sources:
  • DataSourceControls - SqlDataSource, ObjectDataSource, LinqDataSource etc.;
  • LINQ - LINQ queries at runtime;
  • Collections (generic & non-generic) - IList, IEnumerable, etc.;
  • DataSet / DataTable;
  • Declarative

The ComboBox presented in this sample is populated from a SqlDataSource control.
This is done by setting the DataSourceID property of the ComboBox to be the ID
of the SqlDataSource control. Also, the DataValueField and DataTextField properties
need to be used to specify the name of the database fields that will be used to populate the
Value and Text properties of the generated ComboBoxItems.



« Back to examples