Intersoft Support Center

Integrate with GridView

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

  1. Drag and drop GridView control to the WebForm.
  2. Bind it to Customers table.
  3. Go to properties and choose a ContactName column from Columns collection.
  4. Click Convert this field into a TemplateField.
  5. Right click on GridView and choose EditTemplate, ContactName.
  6. Drag and drop a WebCombo control to ContactName cell in GridView EditTemplate.
  7. Bind WebCombo to AccessDataSource with DisplayMember and ValueMember to ContactName.
  8. Add an event to GridView control called GridView1_RowCreated and put the following code:

    C# Copy 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;
          }
       }
    }                     
    

  9. Add an event to FormView control called GridView1_RowUpdating and put the following code:

    C# Copy 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>");
    }                      
    
Previous Next