Gridview controls (from the Internet)

Source: Internet
Author: User

1. Method 1: change the background color of a row in the gridview:

:

Practice:
Double-click the onrowdatabound event of the gridview;
Add the generation ** in the gridviewdomainrowdatabound () method in the background, and the last generation ** is as follows:

Front-end code:

View code

<Asp: gridview id = "gridview1" runat = "server" autogeneratecolumns = "false" datakeynames = "ID card number **" performanceid = "sqlperformance1" allowsorting = "true" backcolor = "white" bordercolor = ""# cccccc" borderstyle = "NONE" borderwidth = "1px" cellpadding = "3" font-size = "12px" nrowdatabound = "gridview1_rowdatabound"> <columns> <asp: boundfield datafield = "ID card number **" headertext = "ID card number **" readonly = "true" sortexpression = "ID card number **"/> <asp: boundfield datafield = "name" headertext = "name" sortexpression = "name"/> <asp: boundfield datafield = "Home Address" headertext = "Home Address" sortexpression = "Home Address"/> <asp: boundfield datafield = "Postal editing **" headertext = "Postal editing **" sortexpression = "Postal editing **"/> </columns> <footerstyle. backcolor = "white" forecolor = "#000066"/> <rowstyle. forecolor = "#000066"/> <selectedrowstyle. backcolor = "#669999" font-bold = "true" forecolor = "white"/> <pagerstyle. backcolor = "white" forecolor = "#000066" horizontalalign = "Left"/> 

Background code:

View code

Protected void gridview1_rowdatabound (Object sender, gridviewroweventargs e) {int I; // executes the loop to ensure that each piece of data can be updated for (I = 0; I <gridview1.rows. count; I ++) {// first, judge whether it is a data row if (E. row. rowtype = datacontrolrowtype. datarow) {// change the background color when the mouse stays. E. row. attributes. add ("onmouseover", "c = This. style. backgroundcolor; this. style. backgroundcolor = '# 00a9ff' "); // the background color e is restored when the mouse is removed. row. attributes. add ("onmouseout", "this. style. backgroundcolor = C ");}}}

 

Related Article

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.