我有一个包含21行的Gridview控件。其中一些行的值为0。我的要求是将背景颜色(由0值行组成)设置并隐藏值(即0)。我能够设置背景颜色。但问题是,我无法隐藏行值。我已经编写了以下代码:gridSellIn.Rows [0] .Visible = false; 整个行都被隐藏了。确保我可以显示带有背景颜色但没有值的行。在asp.net中是否可能实现这一点?
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (...){
//hide controls
foreach (Control c in e.Row.Controls)
{
c.Visible=false;
}
//change color
e.Row.Style.Add("background-color","red");
}
}
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Text = "";
}
protected void GRIDVIEW_DataBinding(object sender, EventArgs e)
{
foreach(GridViewRow grv in GRIDVIEW.Rows)
{
grv.Visible = (Condition_to_check_if_value_loaded_is_zero);
}
}