在某些情况下,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')");
}
}
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')");
}
}