在VS2005的Grid中,有一个选择事件,,但我们在界面上显示的时候,总觉得很别扭,,不是那么自然,于是我们就总得把这个按钮去掉(或是隐藏)。下面是我的实现方法:
不过,我这里的实现方法都还是基于Grid的选择事件来实现的。
一种方式:(1)设置Grid的属性 AutoGenerateSelectButton="true"
              (2)在Grid的RowDataBound事件写如下代码:
                     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
                    {
                        if (e.Row.RowType == DataControlRowType.DataRow)
                        {
                                e.Row.Attributes.Add("onclick", "this.cells[0].childNodes[0].click()");
                        }
                    }
               (3)在Grid的RowCreated事件里隐藏“选择”按钮,代码如下:
                      protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
                      {
                            if (e.Row.RowType == DataControlRowType.DataRow)
                                e.Row.Cells[0].Attributes.Add("style", "display:none;");
                     }
二种方式:(1)设置Grid的属性 AutoGenerateSelectButton="false",但这里需要在前台加如下的代码:
                      <asp:CommandField ShowSelectButton="true" SelectText=" " >
                              <ItemStyle Width="10px" />
                      </asp:CommandField>
                     我们把按钮文本显示为空,然后再设列的宽度。
              (2)在Grid的RowCreated事件里隐藏“选择”按钮,代码如下:
                     protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
                     {
                          if (e.Row.RowType == DataControlRowType.DataRow)
                                e.Row.Attributes.Add("onClick", "javascript:__doPostBack('GridView1','Select$"+e.Row.RowIndex+"')");                    
                    }

    

posted on 2008-07-11 11:40  碰听明  阅读(1853)  评论(0)    收藏  举报