1、首先在.aspx页面块中添加javascript
<script type="text/javascript">
var prevselitem=null;
function selectx(row)
{
if(prevselitem!=null)
{
prevselitem.style.backgroundColor='#eeeeee';
}
row.style.backgroundColor='PeachPuff';
prevselitem=row;
}
</script>
2、然后修改GridView,添加事件OnRowDataBound
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" Width="100%" PageSize="55" OnRowDataBound="GridView1_RowDataBound"></asp:GridView>
3、最后在.aspx.cs页面中添加GridView1_RowDataBound
protected void GridView1_RowDataBound(object sender,GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", e.Row.ClientID.ToString() + ".checked=true;selectx(this)");//点击行变色
}
}
|