You must Sign In to post a response.
  • Category: Windows

    After binding my datagridview with database query i am not able to edit a particular cell

    Hi all ,

    I have bind the datagridview with database query (select query in Store procedure). data is getting bind , i am able to see the data in datagridview properly . but now i want to make a cell of particular column editable means if i click a particular cell the cell should get editable and then i can change the data in the that cell [i dont want to edit it on particular button event] . i have tried many things but didnt work ! please help its urgent !!
  • #765419

    If you want to edit gridview cells then onRowEditing event set the neweditindex like below,

    protected void GV_OnRowEditing(object sender, GridViewEditEventArgs e)
    GV.EditIndex = e.NewEditIndex;
    Bind_GV(); //rebind your grid

    this will enable the textbox controls as per your design it in templatefiled of the gridview,

    If you want to Cancel the Editing then OnCancellingEdit event wrote below line of code.

    protected void GV_OnRowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    GV.EditIndex = -1;

    If you want to update the edited records into database then onRowUpdate event of gridview wrote below lines of code.

    protected void GV_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
    int EmpNo = Convert.ToInt32((GV.Rows[e.RowIndex].FindControl("lblempno") as Label).Text);
    TextBox EName = (TextBox)GV.Rows[e.RowIndex].FindControl("txtename");
    TextBox Job = (TextBox)GV.Rows[e.RowIndex].FindControl("txtjob");

    cmd = new SqlCommand("Update_Employee_Details", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@EMPNO", EmpNo);
    cmd.Parameters.AddWithValue("@Ename", EName.Text);
    cmd.Parameters.AddWithValue("@Job", Job.Text);
    GV.EditIndex = -1;

    Hope this will helpful to you...

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • Sign In to post your comments