c# GridView选择行

来源:互联网 发布:java cs开发实例 编辑:程序博客网 时间:2024/05/29 18:05

郁闷,很简单的代码

 

 

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //当鼠标停留时更改背景色
            //e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");

            //当鼠标移开时还原背景色
            //e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

            
            //当点击一行中任何一个地方的时候,都会触发gridview的SelectedIndexChanged事件,也就是选择事件
            e.Row.Attributes.Add("onclick", "__doPostBack('GridView1','Select$" + e.Row.RowIndex + "')");

        }
    }

原创粉丝点击