<asp:GridView ID="GridView1" runat="server"
onrowdatabound="GridView1_RowDataBound"
style="text-align: center">
</asp:GridView>
后台代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Width = 100;//第一列宽度100单位,默认单位px
e.Row.Cells[1].Width = 120;//第二列宽度120单位,默认单位px
//下面的这个是改变当前行的背景颜色,当鼠标经过时变色
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标经过时,行背景色变
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#00A9FF'");
//鼠标移出时,行背景变回原来的颜色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundCol