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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jayraj ChhayaRank #304 · 8.2K reputationPosted May 15, 2024, 5:12 AM EDT
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.
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GridView1.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound); } } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(GridView1, "Edit$" + e.Row.RowIndex); } } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; // Bind your GridView data here }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.
Kirat17 reputationPosted May 16, 2024, 5:10 AM EDT
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;
}