Asp.net implement two methods to achieve the effects of Row-changing and Optical Rod in GridView

Source: Internet
Author: User

Method 1: work with the frontend and backend
1. aspx row-changing properties (<AlternatingRowStyle BackColor = "# f5f5f5"/>)
Copy codeThe Code is as follows:
<Asp: GridView ID = "gvProjectList" runat = "server"
OnRowCreated = "gvProjectList_RowCreated">
<AlternatingRowStyle BackColor = "# f5f5f5"/>
</Asp: GridView>

1. Set the mouse color on a line in aspx. cs background events
Copy codeThe Code is as follows:
Protected void gvProjectList_RowCreated (object sender, GridViewRowEventArgs e)
{
E. row. attributes. add ("onmouseover", "currentcolor = this. style. backgroundColor; this. style. backgroundColor = '# eaeaea'; "); // This is the background for changing the background of a row when you move the cursor over a row.
E. Row. Attributes. Add ("onmouseout", "this. style. backgroundColor = currentcolor;"); // restore when the mouse moves
}

Method 2: JQuery
1. aspx
First reference jQuery function library, in the http://jquery.com/download, and then write css style, and then add js Code.
Copy codeThe Code is as follows:
<Script src = "jquery-1.5.2.min.js" type = "text/javascript"> </script>

Copy codeThe Code is as follows:
<Style type = "text/css">
. Even {
Background: # F5F5F5;
}
. Odd {
Background: # FFFFFF;
}
. Over {
Background: # CDE6FF;
}
. Tr_chouse {
Background: # 6AB1FF;
}
</Style>

Copy codeThe Code is as follows:
<Script type = "text/javascript">
$ (Document). ready (function (){
$ (". Gridview tr: odd"). addClass ("odd"); // set the odd number of rows to "odd" Style
$ (". Gridview tr: even"). addClass ("even"); // set the even row to "even" Style
$ (". Gridview tr"). mouseover (function () {$ (this). addClass ("over") ;}) // Add the "over" style when mouseover
. Mouseout (function () {$ (this). removeClass ("over") ;}) // remove the "over" style when mouseout.
. Click (function () {$ (this). toggleClass ("tr_chouse");}) // when you click to add or remove the "tr_chouse" style to select data Columns
});
</Script>

February 18, 2013 13:57:30 update]
Copy codeThe Code is as follows:
<Script type = "text/javascript">
$ (Function () {$ (". maingrid_text tr: even "). addClass ("even"); $ (". maingrid_text tr: odd "). addClass ("odd ");
$ (". Maingrid_text tr "). hover (function () {$ (this ). addClass ("table_hover")}, function () {$ (this ). removeClass ("table_hover ")});
});
Function EndRequestHandler (){
$ (Function () {$ (". maingrid_text tr: even "). addClass ("even"); $ (". maingrid_text tr: odd "). addClass ("odd ");
$ (". Maingrid_text tr "). hover (function () {$ (this ). addClass ("table_hover")}, function () {$ (this ). removeClass ("table_hover ")});
});
}
Function reload () {Sys. WebForms. PageRequestManager. getInstance (). add_endRequest (EndRequestHandler );}
$ (Document). ready (function () {reload ();})
</Script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.