方法一:
在GridView的OnRowDataBound事件中设置背景,代码如下:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Attributes.Add("style", "background-image:url('images/title.gif')");
}
}
方法二:
和上面的方法一样,只是代码不一样:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Style.Add("background-image", "images/title.gif");
}
}
方法三:
使用CSS,设置GridView每一列的HeaderStyle的CssClass习性,代码如下:
<style type="text/css">
.headbackground
{
background-image:url(images/title.gif);
}
</style>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="id" HeaderText="编号">
<HeaderStyle CssClass="headbackground" />
</asp:BoundField>
<asp:HyperLinkField DataTextField="title" HeaderText="标题">
<HeaderStyle CssClass="headbackground" />
</asp:HyperLinkField>
</Columns>
</asp:GridView>
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/hfzsjz/archive/2009/06/21/4286440.aspx