有一个GridView
第一列是个checkbox。现在每次单击行(绑定了onclick)会跳到详细页。
点checkbox也会跳到详细页。
如何不让他点击checkbox的时候也跳转?只有点击除了第一列的时候才会跳转?除了为每个cell绑定onclick(每个都绑定,假如有太都字段的话那不晕死了)的方法外还有什么方法?

解决方案 »

  1.   

    每列单独设置onclick
    CheckBox ck = (CheckBox)e.Row.Cells[0].FindControl("CheckBox1");
    ck.Attributes.Add("onclick", "js1()");
    //设置其他单元格的Click
    e.Row.Cells[1].Attributes.Add("onclick", "test()");
    e.Row.Cells[2].Attributes.Add("onclick", "test()");
    e.Row.Cells[3].Attributes.Add("onclick", "test()");
      

  2.   

    在rowdatabound 事件里面绑定吧。
      

  3.   

    使用Nested GridView。 Parent GridView包含两列,分别是ID和CheckBox,不用说,ID列是隐藏的。Child GridView 与 Parent GridView建立一一对应(应用Parent GridView RowDataBound Event来建立关系),在Child GridView RowDataBound事件里定义每行的Click Event。因此,当Click CheckBox列时,没有Event发生;而当Click CheckBox以外的列时,实际上是与Child GridView交互。
      

  4.   

    同意三楼的,在你单击跳转函数里面判断,是CheckBox那列就不跳转了
      

  5.   

    除了每列设置onclick还有其他什么方法?
      

  6.   

    哥,我也知道要判断,主要是要怎么判断?        protected void Grid_Msg_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='E9E9E9'");
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=''");
                    e.Row.Attributes.Add("style", "cursor:pointer");
                    if(e.Row.Cells[0])//接下去要怎么写?
                        e.Row.Attributes.Add("onclick", "window.location.href='/Admin/ManagerReadMsg.aspx?ID=" + ((GridView)sender).DataKeys[e.Row.RowIndex].Values["ID"] + "'");
                }
            }
      

  7.   

    e.Row.Attributes.Add("onclick", "window.location.href='/Admin/ManagerReadMsg.aspx?ID=" + ((GridView)sender).DataKeys[e.Row.RowIndex].Values["ID"] + "'");
    e.Row.Cells[0].Attributes.Add("onclick","");
             
      

  8.   

    10楼有误,应该是:
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                TableCellCollection cells = e.Row.Cells;
                for(int i=1;i<cells.Count;i++)
                    e.Row.Cells[i].Attributes.Add("onclick", "window.open('Default.aspx')");
            }
      

  9.   

    tank you 虽然和一个个e.row.cell.attributes.add原理一样!不过比较省事多了!