Home > DeveloperSection > Forums > How to create gridview updating event dynamically?
Manoj Bhatt
Manoj Bhatt

Total Post:154

Posted on    August-26-2014 2:16 AM

 ASP.Net ASP.Net 

 1 Reply(s)
 762  View(s)
Rate this:

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();


        if (ds.Tables[0].Rows[0] != null)


            GridView1.AutoGenerateEditButton = true;

            GridView1.DataSource = ds;


            GridView1.RowUpdating += new GridViewUpdateEventHandler(abc);

            GridView1.DataKeyNames = new string[] { "id" };

            GridView1.RowEditing += new GridViewEditEventHandler(bc);





    protected void abc(object sender, GridViewUpdateEventArgs e)




    protected void bc(object sender, GridViewEditEventArgs e)


        GridView gv = (GridView)sender;

        gv.EditIndex = e.NewEditIndex;



the row used to get in edit mode only if i edit the next row means first row never get in edited mode.

Sumit Kesarwani

Total Post:378

Posted on    August-26-2014 2:56 AM

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">


You need to add:


so it looks like:

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


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


Don't want to miss updates? Please click the below button!

Follow MindStick