---
title: "How to create gridview updating event dynamically?"  
description: "How to create gridview updating event dynamically?"  
author: "Manoj Bhatt"  
published: 2014-08-26  
updated: 2014-08-26  
canonical: https://www.mindstick.com/forum/2145/how-to-create-gridview-updating-event-dynamically  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# How to create gridview updating event dynamically?

```
public partial class Gridvw_expt2 : System.Web.UI.Page{    SqlCommand com;    SqlDataAdapter da;    DataSet ds;    SqlConnection con= new SqlConnection(ConfigurationManager.ConnectionStrings["gj"].ConnectionString);    protected void Page_Load(object sender, EventArgs e)    {                  com = new SqlCommand("Select * from tblExpt",con);        da = new SqlDataAdapter(com);        ds = new DataSet();        da.Fill(ds);        if(ds.Tables[0].Rows[0] != null)        {           
GridView1.AutoGenerateEditButton = true;           
GridView1.DataSource = ds;           
GridView1.DataBind();           
GridView1.RowUpdating += new GridViewUpdateEventHandler(abc);           
GridView1.DataKeyNames = new string[] { "id" };           
GridView1.RowEditing += new GridViewEditEventHandler(bc);        }            else           
Response.Write("fkj");    }    protected void abc(object sender, GridViewUpdateEventArgs e)    {       
Response.Write(e.RowIndex);    }    protected void bc(object sender, GridViewEditEventArgs e)    {        GridView gv =(GridView)sender;        gv.EditIndex =e.NewEditIndex;    }}
```

the [row](https://www.mindstick.com/forum/1212/this-row-already-belongs-to-this-table) used to get in edit [mode](https://yourviews.mindstick.com/view/81372/us-congress-should-go-in-remote-mode-for-proper-functioning) only if i edit the next row means first row [never](https://yourviews.mindstick.com/view/290/zoos-prisons-for-beings-who-have-never-committed-a-crime) get in edited mode.

## Replies

### Reply by Sumit Kesarwani

Hi Manoj,

Its because you haven't set up a handler to handle GridView.RowEditing. On your gridview (in the .aspx) you need to wire up a method which will deal with RowEditing.

You're gridview code will look like:

<asp:GridView ID="GridView1" runat="server">

</asp:GridView>

You need to add:

OnRowEditing="nameOfMethodYouWantToFire"

so it looks like:

<asp:GridView ID="GridView1" runat="server" OnRowEditing="nameOfMethodYouWantToFire">

</asp:GridView>

Where nameOfMethodYouWantToFire is in your code behind (your C#) and it handles the event. Something like this:

protected void nameOfMethodYouWantToFire(object sender, GridViewPageEventArgs e)

{

//Your code here

}


---

Original Source: https://www.mindstick.com/forum/2145/how-to-create-gridview-updating-event-dynamically

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
