如何GridView中单击一行等效于触发SelectButton事件?即单击某一数据行后,高亮显示该行;而不是使用<asp:CommandField ShowSelectButton="True" /> 来达到这一效果的。
    请问如何实现?谢谢!
    我看页面生成的javascript,在后台代码中添加如下,可实现,不过似乎不好,要将页面设置为 enableEventValidation="false" :
    protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {                      
            e.Row.Attributes.Add("style", "cursor:hand;");
            e.Row.Attributes.Add("onclick", string.Format("__doPostBack('GridView', 'Select${0}');", e.Row.DataItemIndex));
        }
    }

解决方案 »

  1.   

    参考一下选择DataGrid中的CheckBox控件后该行背景变色 
    http://blog.csdn.net/fengfangfang/category/141385.aspx
      

  2.   

    转为模板列    <ItemTemplate>
                    <div style="width: 220px" title ='<%# Eval("名称") %>' class="my_nowrap">
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Select"
                            Text='<%# Eval("名称") %>'></asp:LinkButton></div>
                    </ItemTemplate>
      

  3.   

    e.Row.Attributes.Add("onclick", "highlight(this);");function highlight(o){
      e = o;
      o = o.parentElement;
      while(o!=null && o.tagName != "TABLE"){
         o = o.parentElement;
      }
      for(var i =0;i<o.rows.length;i++){
        o.rows[i].style.backgroundColor = "white";
      }
      e.style.backgroundColor = "red";
    }
      

  4.   

    我是想不用<asp:CommandField ShowSelectButton="True" />,而是单击某一数据行(该行的任何地方都可以),来实现选择某一数据行的效果。因为后续,我还要对该行进行操作(不在GridView里面了,而是GridView外边有一系列操作按钮,比如删除、查看详细情况的按钮等)。这时,我可以通过GridView.SelectedRow.RowIndex来获取我要的那一行数据。
      

  5.   

    我只会选一列 
    我做了几个也是你一样
    我只选一列 把值(比如 id)传到TextBox.Text
    然后以此为引子操作
      

  6.   

    e.Row.Attributes.Add("onclick", "highlight(this);");function highlight(o){
      e = o;
      o = o.parentElement;
      while(o!=null && o.tagName != "TABLE"){
         o = o.parentElement;
      }
      for(var i =0;i<o.rows.length;i++){
        o.rows[i].style.backgroundColor = "white";
      }
      e.style.backgroundColor = "red";
    }
    这样就跟CommandField无关了
      

  7.   

    我是想和CommandField无关,又达到CommandField的效果。利用单击某一数据行,而不是CommandField。
      

  8.   

    e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='LightGoldenrodYellow'") ;
      

  9.   

    同 http://community.csdn.net/Expert/topic/4888/4888654.xml?temp=.4237024