Combobox loading data from store which uses an SqldataSource. It shows Name field, and returns SportID field value:
The method in code behind could be as follows:
protected void Store2_ReadData(object sender, StoreReadDataEventArgs e)
{
using (var db = new ClubSiteContext())
{
Store store = this.cbxDeportes.GetStore();
store.DataSource = from s in db.Sports select new { s.SportID, s.Name };
store.DataBind();
}
}
In this case is important to perform an initial load for the data when the page is loaded.
Other way to load data is using a SqlDataSource like this:
Once we have data loaded into the combobox, we could select an item, or select the empty item described using the tag EmptyText as follows:
if (aRaceType.SportID == 0)
cbxDeportes.Value = "";
else
{
object SportID = aRaceType.SportID;
cbxDeportes.Select(SportID);
}
If we want to perform some kind of action when user selects a value from combobox we could use Direct Events an a method in code behind like this:
And this is the method implemented in code behind:
protected void cbRaceTypesChangeValue(object sender, DirectEventArgs e)
{
txbxPoints.Text = "Escribe algo";
}
More combobox samples here http://examples.ext.net/#/Form/ComboBox/Overview/
No hay comentarios:
Publicar un comentario