forum

Home / DeveloperSection / Forums / How to create gridview updating event dynamically?

How to create gridview updating event dynamically?

Manoj Bhatt 1690 26-Aug-2014
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 used to get in edit mode only if i edit the next row means first row never get in edited mode.


Updated on 26-Aug-2014

Can you answer this question?


Answer

1 Answers

Liked By