2 Methods of ASP.net gridview interlacing and Light stick effect _ practical skills

Source: Internet
Author: User
method One: The foreground and backstage use together
1.aspx interlacing Properties (<alternatingrowstyle backcolor= "#f5f5f5"/>)
Copy Code code as follows:

<asp:gridview id= "gvprojectlist" runat= "Server"
onrowcreated= "gvprojectlist_rowcreated" >
<alternatingrowstyle backcolor= "#f5f5f5"/>
</asp:GridView>

1.aspx.cs background Events Set the mouse to change the color effect on a line
Copy Code code 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 that changes a row when the mouse moves to a line
E.row.attributes.add ("onmouseout", "this.style.backgroundcolor=currentcolor;"); /restore when Mouse is moved
}

method Two: jquery Way
1.aspx
First refer to the JQuery function library, download in http://jquery.com/, then write CSS style, and then add JS code.
Copy Code code as follows:

<script src= "Jquery-1.5.2.min.js" type= "Text/javascript" ></script>

Copy Code code as follows:

<style type= "Text/css" >
. even {
Background: #F5F5F5;
}
. Odd {
Background: #FFFFFF;
}
. over{
Background: #CDE6FF;
}
. tr_chouse {
Background: #6AB1FF;
}
</style>

Copy Code code as follows:

<script type= "Text/javascript" >
$ (document). Ready (function () {
$ (". GridView Tr:odd"). AddClass ("odd"); Odd line set to "odd" style
$ (". GridView Tr:even"). AddClass ("even"); Even-numbered rows are set to the "even" style
$ (". GridView tr"). MouseOver (function () {$ (this). addclass (' over ');})///When mouseover adds the over style
. mouseout (function () {$ (this). Removeclass (' over ');})//When mouseout is removed the over style
. Click (function () {$ (this). Toggleclass ("Tr_chouse");})//When Click joins or removes the "Tr_chouse" style, implement data column selection
});
</script>

February 18, 2013 13:57:30 Update
Copy Code code 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.