Can we edit the grid view by clicking on row any where without edit button in asp.net c#?
Loading
Can we edit the grid view by clicking on row any where without edit button in asp.net c#?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jayraj ChhayaPosted May 15, 2024, 9:12 AM
you can achieve the functionality of editing a GridView row by clicking anywhere on the row without an edit button by utilizing JavaScript along with GridView events. You can handle the row click event using JavaScript and then trigger the GridView row editing programmatically.
By attaching a JavaScript click event to the GridView rows and handling the row editing logic in the code-behind, you can enable row editing by clicking anywhere on the row without the need for a specific edit button.
KiratPosted May 16, 2024, 9:10 AM
protected void OnRowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "javascript:this.style.cursor='hand';this.style.backgroundColor='#BAE0F2';");
e.Row.Attributes.Add("onmouseout", "javascript:this.style.cursor='hand';this.style.backgroundColor='#FFFFFF';");
e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(GridView1, "Select$" + e.Row.RowIndex);
e.Row.ToolTip = "Click to edit this row.";
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
label1.Text = GridView1.SelectedRow.Cells[0].Text;
}