ASP.NET ComboBox - Populating with Data - SqlDataSource
Zimbabwe
230
Zambia
229
Yemen
228
Wallis and Futuna
227
Wales
226
Virgin Islands
225
Vietnam
224
Venezuela
223
Vatican City
222
Vanuatu
221
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