最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How can I add an onclick event to just the first column of a gridview and not the entire row? - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 6

Add 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);");

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论