<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> <mce:script language="javascript" type="text/javascript"><!-- var oldRow = null; window.οnlοad=function() { var tblId = "<%=GridView1.ClientID %>"; var tbl = $e(tblId); if(tbl!=null) { for(var i=1;i<tbl.rows.length;i++) { tbl.rows[i].οnclick=new Function("clickRow(this)") } } } function clickRow(row) { var colorHighlt = "red"; //alert(row.rowIndex); if(oldRow!=row) { if(oldRow!=null) { oldRow.style.backgroundColor = ""; } row.style.backgroundColor = colorHighlt; }else { row.style.backgroundColor=(row.style.backgroundColor==""?colorHighlt:""); } var lblId = "<%=Lbl1.ClientID %>"; var lbl = $e(lblId); lbl.innerText = row.cells(0).innerText;//Label更新为当前行第一列的值 oldRow = row; } function $e(id) { return document.getElementById(id); } // --></mce:script> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Lbl1" runat="server" Text="初始值"></asp:Label> <asp:GridView runat="server" ID="GridView1" Width="50%"> </asp:GridView> </div> </form> </body> </html>