vb.net 如何在asp.net中隐藏Gridview行值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14977977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to hide Gridview row values in asp.net
提问by shankar.parshimoni
I have Gridview control with 21 rows.Some of the rows have 0 values.My requirement is to set background color(consist 0 values Rows) as well as hide the values(means 0's).I can able to set background color.But the thing is,I am not able to hide row values.I have written this line of code, gridSellIn.Rows[0].Visible = false; .Total row is hiding.Make sure i have to show rows back ground color without values.Is this possible in asp.net.
我有 21 行的 Gridview 控件。一些行有 0 个值。我的要求是设置背景颜色(包含 0 个值行)以及隐藏值(意味着 0)。我可以设置背景颜色。但是问题是,我无法隐藏行值。我写了这行代码 gridSellIn.Rows[0].Visible = false; .总行正在隐藏。确保我必须显示没有值的行背景颜色。这在asp.net中是否可行。
采纳答案by Stefano Altieri
In the grid RowDataBound event:
在网格 RowDataBound 事件中:
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");
}
}
回答by Ratna
In GridView1_RowDataBound event do the following with rows in which you want no values.
在 GridView1_RowDataBound 事件中,对不需要值的行执行以下操作。
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Text = "";
}
回答by talisman027
You could do this is the DataBinding Event.
您可以通过 DataBinding 事件执行此操作。
protected void GRIDVIEW_DataBinding(object sender, EventArgs e)
{
foreach(GridViewRow grv in GRIDVIEW.Rows)
{
grv.Visible = (Condition_to_check_if_value_loaded_is_zero);
}
}

