WebCombo is already compatible with the standard infrastructure Microsoft's
FormView EditTemplate.
In this topic, you will learn how to integrate WebCombo to FormView.
To integrate WebCombo to FormView
- Drag and drop FormView control to the WebForm.
- Bind it to Customers table.
- Right click on FormView and choose EditTemplate, EditItemTemplate.
- Drag and drop a WebCombo control to ContactName cell in
FormView EditTemplate.
- Bind WebCombo
to AccessDataSource with DisplayMember and ValueMember
to ContactName.
- Add an event to FormView control called FormView1_ItemCreated and
put the following code:
protected void FormView1_ItemCreated(object sender, EventArgs e)
{
if (FormView1.Row.RowState == DataControlRowState.Edit)
{
DataRowView rowView = FormView1.DataItem as DataRowView;
if (rowView != null)
{
string contactName = rowView.Row.ItemArray[2] as string;
WebCombo combo = FormView1.FindControl("WebCombo1") as WebCombo;
combo.Value = contactName;
}
}
}
|
- Add an event to FormView control called FormView1_ItemUpdating
and put the following code:
protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
WebCombo combo = FormView1.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>");
}
|