除第一列外,Gridview行可单击吗?

MAW*_*656 6 c# asp.net gridview

我正在使用以下代码使我的gridview的整行可单击:

 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);
        }
    }
Run Code Online (Sandbox Code Playgroud)

哪个效果很好,除了现在我想为网格添加编辑功能.这很有效,但是当我打开行可点击和编辑功能时,单击"编辑"链接按钮通常会触发行单击事件,反之亦然.

那么,除了指定的列之外,如何保持行可点击?

更新:这是我正在使用的.

基于Justin的解决方案:

 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);
     }
 }
Run Code Online (Sandbox Code Playgroud)

Jus*_*n C 4

诀窍是注册需要可点击的特定列上的点击。下面的代码假设您知道应该可点击的索引(在本例中为 0)。

e.Row.Cells[0].Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(this.gridMSDS, "Select$" + e.Row.RowIndex);
Run Code Online (Sandbox Code Playgroud)