Intersoft Support Center

Integrate WebInput to GridView

You can integrate WebInput to GridView.

In this topic, you will learn how to integrate WebInput to GridView.

To integrate WebInput to GridView

  1. In GridView1_RowCreated event handler function, put the following code:
    C# Copy ImageCopy 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)
          {
             WebInput wiBirthDate = e.Row.Cells[5].FindControl("wiBirthDate") as WebInput;
                                            
             if (wiBirthDate!=null)
                wiBirthDate.Value = (DateTime) drv["BirthDate"];
                    
             WebInput wiHireDate = e.Row.Cells[6].FindControl("wiHireDate") as WebInput;
                    
             if (wiHireDate != null)
                wiHireDate.Value = (DateTime) drv["HireDate"];
                    
             WebInput wiHomePhone = e.Row.Cells[12].FindControl("wiHomePhone") as WebInput;
                    
             if (wiHomePhone!=null)
                wiHomePhone.Value = drv["HomePhone"] as string;
                    
             WebInput wiExtension = e.Row.Cells[13].FindControl("wiExtension") as WebInput;
                    
             if (wiExtension!=null)
                wiExtension.Value = drv["Extension"] as string;
          }
       } 
    }
    

  2. In GridView1_RowUpdating event handler function, put the following code:
    C# Copy ImageCopy Code
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {               
       System.Web.UI.WebControls.GridView grid = sender as System.Web.UI.WebControls.GridView;
            
       WebInput wiBirthDate = grid.Rows[e.RowIndex].Cells[5].FindControl("wiBirthDate") as WebInput;
       e.NewValues.Add("BirthDate", wiBirthDate.Value);
            
       WebInput wiHireDate = grid.Rows[e.RowIndex].Cells[6].FindControl("wiHireDate") as WebInput;
       e.NewValues.Add("HireDate", wiHireDate.Value);
               
       WebInput wiHomePhone = grid.Rows[e.RowIndex].Cells[12].FindControl("wiHomePhone") as WebInput;
       e.NewValues.Add("HomePhone", wiHomePhone.Text);
               
       WebInput wiExtension = grid.Rows[e.RowIndex].Cells[13].FindControl("wiExtension") as WebInput;
       e.NewValues.Add("Extension", wiExtension.Text);
    }
    
    
    
Previous Next