1. Add the ridiobutton control to the gridview. < ASP: gridview ID = "Gridview1" Runat = "Server"
Performanceid = "Objectperformance1" Skinid = "Common" Onrowdatabound = "Gridview1_rowdatabound" >
< Columns >
< ASP: boundfield Datafield = "Depid" Headertext = "Department ID" Sortexpression = "Depid" />
< ASP: boundfield Datafield = "Depname" Headertext = "Department name" Sortexpression = "Depname" />
< ASP: boundfield Datafield = "Principal" Headertext = "Owner" Sortexpression = "Principal" />
< ASP: boundfield Datafield = "Depmemo" Headertext = "Remarks" Sortexpression = "Depmemo" />
< ASP: templatefield Insertvisible = "False" >
< Itemtemplate >
< Input ID = '<% # "Select _" + Databinder. eval (container, "dataitem. depid") % > 'Name = "select" type = "radio"/>
</ Itemtemplate >
</ ASP: templatefield >
</ Columns >
</ ASP: gridview >
2. Write color changes in the rowdatabound event of the gridview Code Protected Void Gridview1_rowdatabound ( Object Sender, gridviewroweventargs E)
{
If (E. Row. rowtype = Datacontrolrowtype. datarow)
{
Datarowview row = (Datarowview) E. Row. dataitem;
String ID = Row [ " Depid " ]. Tostring ();
E. Row. Attributes. Add ( " Onclick " , " Select " + ID + " Checked = true; " );
}
If (E. Row. rowtype = Datacontrolrowtype. datarow)
{
E. Row. Attributes. Add ( " Onmouseover " , " If (this! = PREV) {c = This. style. backgroundcolor; this. style. backgroundcolor = '# d8f3c6 '} " ); // Change the background color when the mouse stays
E. Row. Attributes. Add ( " Onmouseout " , " If (this! = PREV) {This. style. backgroundcolor = c} " ); // Restore the background color when you move the mouse away.
E. Row. attributes [ " Style " ] = " Cursor: Hand " ; // Set the floating mouse pointer to "little hand"
// Datarowview ROW = (datarowview) E. Row. dataitem;
// String id = row ["depid"]. tostring ();
// E. Row. Attributes. Add ("onclick", "select _" + E. Row. cells [0]. Text + ". Checked = true ;");
E. Row. Attributes. Add ( " Onclick " , " Select _ " + E. Row. cells [ 0 ]. Text + " . Checked = true; selectx (this) " );
}
}
3. Write control functions in front-end JS scripts < Script Language = "JavaScript" Type = "Text/JavaScript" >
VaR Prev = Null ;
Function Selectx (ROW) /**/ /*Change the color of the selected row to the color of the selected row.*/
{
If (Prev ! = Null )
{
Prev. style. backgroundcolor='# E4f7d8 ';
}
Row. style. backgroundcolor = '# 8ec26f ';
Prev = Row;
}
</ Script >
Finally, remember to use request. Form ["select"] in the background to receive the selected value. In addition, you can hide the radiobuttou for better results.