I'm using the following code to make the entire row of my gridview clickable:
protected void gridMSDS_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.textDecoration='underline';this.style.backgroundColor='#EEFF00'";
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';this.style.backgroundColor='White'";
e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.gridMSDS, "Select$" + e.Row.RowIndex);
}
}
Which works great, except now I want to add edit ability to the grid. This works, but when I have both the row clickable and editing functions turned on, clicking the "Edit" link button often fires the row click event and vice versa.
So, how can I keep row clickable, except for specified columns?
UPDATE: Here's what I'm using.
Based on Justin's solution:
List<int> notClickable = new List<int>();
{
notClickable.Add(0);
notClickable.Add(2);
}
for(int i = 0; i < e.Row.Cells.Count; i++)
{
if (!notClickable.Contains(i))
{
e.Row.Cells[i].Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(this.gridMSDS, "Select$" + e.Row.RowIndex);
}
}
The trick is the register the click on the specific columns that need to be clickable. The code below assumes you know the indexes that should be clickable (in this case 0).
e.Row.Cells[0].Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(this.gridMSDS, "Select$" + e.Row.RowIndex);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With