WebCombo is already compatible with the standard infrastructure Microsoft's
GridView.
In this topic, you will learn how to integrate WebCombo to GridView.
To integrate WebCombo to GridView
- Drag and drop GridView control to the WebForm.
- Bind it to Customers table.
- Go to properties and choose a ContactName column
from Columns collection.
- Click Convert this field into a TemplateField.
- Right click on GridView and choose EditTemplate, ContactName.
- Drag and drop a WebCombo control to ContactName cell in
GridView EditTemplate.
- Bind WebCombo
to AccessDataSource with DisplayMember and ValueMember
to ContactName.
- Add an event to GridView control called GridView1_RowCreated and
put the following code:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowState == DataControlRowState.Edit)
{
DataRowView drv = e.Row.DataItem as DataRowView;
if (drv != null)
{
TableCell contactNameCell = e.Row.Cells[3];
WebCombo combo = contactNameCell.FindControl("WebCombo1") as WebCombo;
combo.Value = drv["ContactName"] as string;
}
}
}
|
- Add an event to FormView control called GridView1_RowUpdating and
put the following code:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
System.Web.UI.WebControls.GridView grid = sender as System.Web.UI.WebControls.GridView;
WebCombo combo = grid.Rows[e.RowIndex].Cells[3].FindControl("WebCombo1") as WebCombo;
e.NewValues.Add("ContactName", combo.Text);
ClientScript.RegisterClientScriptBlock(
typeof(Page),"result",
"<script language='JScript'>alert('Your selection is: " + combo.Text + "');</script>");
}
|