为GridView控件的数据行添加鼠标动作

来源:互联网 发布:教学质量监控网络 编辑:程序博客网 时间:2024/06/06 05:52

前台:

 <div>

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"

            OnRowCreated="GridView1_RowCreated">

            <Columns>

                <asp:BoundField DataField="StuID" HeaderText="StuID" SortExpression="StuID" />

                <asp:BoundField DataField="Stuname" HeaderText="Stuname" SortExpression="Stuname" />

                <asp:BoundField DataField="Stuage" HeaderText="Stuage" SortExpression="Stuage" />

                <asp:BoundField DataField="Grade" HeaderText="Grade" SortExpression="Grade" />

            </Columns>

        </asp:GridView>

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$  

                   ConnectionStrings:DatabindControlsConnectionString %>"

            SelectCommand="SELECT [StuID], [Stuname], [Stuage], [Grade] FROM [student]"></asp:SqlDataSource>

 

    </div>

 

后台:

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)

    {

        if (e.Row.RowType ==DataControlRowType.DataRow)

        {

            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FF0000'");

            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

        }

    }

原创粉丝点击