Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Gridview行是否可单击(第一列除外)?_C#_Asp.net_Gridview - Fatal编程技术网

C# Gridview行是否可单击(第一列除外)?

C# Gridview行是否可单击(第一列除外)?,c#,asp.net,gridview,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';t

我使用以下代码使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);
        }
    }
这非常有效,除了现在我想在网格中添加编辑功能。这是可行的,但当我同时打开行可单击和编辑功能时,单击“编辑”链接按钮通常会触发行单击事件,反之亦然

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

更新: 这是我用的

基于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);
     }
 }
List notClickable=新建列表();
{
不可点击。添加(0);
不可点击。添加(2);
}
for(int i=0;i
诀窍在于注册需要单击的特定列。下面的代码假设您知道应该可以单击的索引(在本例中为0)


我应该把这个代码放在哪里?我可以在行中的单元格中循环,使单元格2-n可点击吗?将其准确地放在当前编码的onclick位置。用e.Row.Cells[0].Attributes替换e.Row.Attributes行。@MAW74656-是的,您可以在单元格中循环。e、 Row.Cells.Length我相信它给出了单元格的数量,可能是e.Row.Cells.Count.Perfect,我会尽快尝试,然后我会接受答案。
e.Row.Cells[0].Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(this.gridMSDS, "Select$" + e.Row.RowIndex);