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.
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.
Share Improve this question asked Nov 28, 2012 at 21:39 FreakishlyFreakishly 1,5715 gold badges32 silver badges62 bronze badges 1-
javascript:void
is useless – epascarello Commented Nov 28, 2012 at 21:41
2 Answers
Reset to default 6Add it to e.Row.Cells[0]
instead
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Attributes.Add("onClick", "SelectRow(this);");
}
Try:
e.Row.Cells[0].Attributes.Add("onClick", "javascript:void SelectRow(this);");