Gridview的行可点击除了第一列? [英] Gridview row clickable except for first column?

查看:61
本文介绍了Gridview的行可点击除了第一列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using the following code to make the entire row of my gridview clickable:

 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);
        }
    }

除了我现在要向网格添加编辑功能之外,这还不错.这可行,但是当我同时打开了行可点击和编辑功能时,单击编辑"链接按钮通常会触发行单击事件,反之亦然.

Which works great, except now I want to add edit ability to the grid. This works, but when I have both the row clickable and editing functions turned on, clicking the "Edit" link button often fires the row click event and vice versa.

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

So, how can I keep row clickable, except for specified columns?

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

UPDATE: Here's what I'm using.

基于贾斯汀的解决方案:

Based on Justin's solution:

 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);
     }
 }

推荐答案

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

The trick is the register the click on the specific columns that need to be clickable. The code below assumes you know the indexes that should be clickable (in this case 0).

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

这篇关于Gridview的行可点击除了第一列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆