Protected void gridview1_rowdatabound (Object sender, gridviewroweventargs E)
{
If (E. Row. rowtype = datacontrolrowtype. datarow)
{
String key = This. gridview1.datakeys [E. Row. rowindex]. value. tostring ();
E. Row. Attributes. Add ("onmouseover", "If (this! = Prevselitem) {This. style. backgroundcolor = '# efefefef'}; this. style. cursor = 'hand'; "); // change the background color when the mouse stays
E. Row. Attributes. Add ("onmouseout", "If (this! = Prevselitem) {This. style. backgroundcolor = '# ffff'} "); // restore the background color when you move the mouse away.
E. row. attributes. add ("onclick", E. row. clientid. tostring () + ". checked = true; selectx (this); setvalue ('"+ key + "')");
// E. Row. Attributes. Add ("onclick", "alert ('" + key + "')");
}
}
<SCRIPT type = "text/JavaScript">
VaR prevselitem = NULL;
Function selectx (ROW)
{
If (prevselitem! = NULL)
{
Prevselitem. style. backgroundcolor = '# ffff ';
}
Row. style. backgroundcolor = 'peachpuff ';
Prevselitem = row;
}
Function setvalue (OBJ)
{
Document. getelementbyid ("hidden1"). value = OBJ;
Document. getelementbyid ("DD"). innerhtml = OBJ;
Alert (OBJ );
Document. All ('button1'). Click ();
}
</SCRIPT>