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 ");}}}