后台行绑定事件里直接给行对象添加Attributes
比如
e.row.Attributes.add("onclick","alert("+ index +")");
这样点击行后就会执行脚本了,index是循环加出来地

解决方案 »

  1.   

    直接取好象有点困难!!
    可以这样:
    在GridView的RowDataBound设置一下:
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onclick", "test(" + e.Row.RowIndex + ")");
                e.Row.Attributes.Add("style", "cursor: hand;");
            }
        }js获得:
        <script type="text/javascript">
        function test(mySelect)
        {
            alert(mySelect);
        }
        </script>
      

  2.   

    如果点击时不想刷新页面就改成如下所示: protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
        { 
            if (e.Row.RowType == DataControlRowType.DataRow) 
            { 
                e.Row.Attributes.Add("onclick", "test(" + e.Row.RowIndex + ");return false;"); 
                e.Row.Attributes.Add("style", "cursor: hand;"); 
            } 
        } js获得: 
        <script type="text/javascript"> 
        function test(mySelect) 
        { 
            alert(mySelect); 
        } 
        </script>