Reputation: 1571
Title is pretty self-explanatory. I have a gridview, and when the user clicks on a particular row, I add a shadow to the first column. The problem is, the user can click anywhere on the row, and the shadow is added, but the link is only opened in a new tab if the user clicks on the link (i.e. first column). How do I add the onclick event to the first column of every row only?
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Javascript function to call on row-click event
e.Row.Attributes.Add("onClick", "javascript:void SelectRow(this);");
}
If it helps, I used the example here to implement SelectRow.
Upvotes: 2
Views: 3589
Reputation: 3635
Try:
e.Row.Cells[0].Attributes.Add("onClick", "javascript:void SelectRow(this);");
Upvotes: 2
Reputation: 55740
Add it to e.Row.Cells[0]
instead
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Attributes.Add("onClick", "SelectRow(this);");
}
Upvotes: 6