【发布时间】:2012-09-04 17:14:16
【问题描述】:
有可能吗?我只能设置单元格的背景颜色。事情是,如果我设置背景颜色,它不会在您打印页面时显示(默认情况下)。所以我想通过 css 将背景设置为网格单元格,但在 BoundField.ItemStyle 类中找不到这个属性(只有'backgroundColor')。那么,这有可能吗?
提前致谢
【问题讨论】:
有可能吗?我只能设置单元格的背景颜色。事情是,如果我设置背景颜色,它不会在您打印页面时显示(默认情况下)。所以我想通过 css 将背景设置为网格单元格,但在 BoundField.ItemStyle 类中找不到这个属性(只有'backgroundColor')。那么,这有可能吗?
提前致谢
【问题讨论】:
试试这个:
在后面代码中的 RowDataBound 事件中,您可以获取您需要的单元格的 System.Web.UI.WebControls.TableCell 对象,并使用 CssClass 属性设置其样式:
e.Row.Cells[0].CssClass = "myStyle"
【讨论】:
如果您想在网格视图上按每个单元格而不是行来添加它
ItemStyle-CssClass="class name here"
【讨论】:
您可以在 GridView 上设置 RowStyle-CssClass 属性,然后将样式应用于您拥有 CSS 样式的单元格(外部样式表、头部等...)。
【讨论】:
你可以试试
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
if(condition)//Replace with your condition
{
e.Row.Cells[5].Attributes.Add("Style", "background: url(../Images/test.png) no-repeat 5px center
}
}
}
【讨论】: