在DataGrid和GridView中对表头设定背景图片

在某些情况下,DataGrid或者GridView的默认样式并不能满足日益高涨的用户的要求,很多人追求美观的样式。对表头设定背景也是其中的一个方面,那么有什么好的方法可以达到这一要求呢,我的方法如下:
DataGrid:

private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
    
if(e.Item.ItemType == System.Web.UI.WebControls.ListItemType.Header)
    {
        e.Item.Attributes.Add(
"style""background-image:url('background.gif')");
    }
}

GridView:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    
if (e.Row.RowType == DataControlRowType.Header)
    {
        e.Row.Attributes.Add(
"style""background-image:url('background.gif')");
    }
}

posted @ 2006-12-29 12:59  眼里进了砂  阅读(546)  评论(0编辑  收藏  举报