如何隐藏gridview中具有空值的列。 [英] How to hide column which have null values in gridview.
本文介绍了如何隐藏gridview中具有空值的列。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在gridview中隐藏nullvalues列。我被卡住了隐藏空值列。我隐藏空值列但标题也被隐藏。
COde snnip如下:
I want to hide nullvalues column in gridview. I got stuck to hide null values column. i hide null values column but header was also hided.
COde snnip is below:
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
// Make sure there are at least header row
if (GridView1.HeaderRow != null)
{
int columnIndex = 0;
// For each column
foreach (DataControlFieldCell clm in GridView1.HeaderRow.Cells)
{
bool notAvailable = true;
// For each row
foreach (GridViewRow row in GridView1.Rows)
{
string columnData = row.Cells[columnIndex].Text;
if (!(string.IsNullOrEmpty(columnData) || columnData== " "))
{
notAvailable = false;
break;
}
}
if (notAvailable)
{
// Hide the target header cell
GridView1.HeaderRow.Cells[columnIndex].Visible = true
;
// Hide the target cell of each row
foreach (GridViewRow row in GridView1.Rows)
row.Cells[columnIndex].Visible = false;
}
columnIndex++;
}
}
}
推荐答案
/ protected void GridView1_RowDataBound(对象发送者,GridViewRowEventArgs e)
// {
// //确保至少有标题行
//如果(GridView1.HeaderRow!= null)
// {
// int columnIndex = 0;
// //对于每一列
// foreach(GridView1.HeaderRow.Cells中的DataControlFieldCell clm)
// {
// bool notAvailable = true;
// //每一行
// foreach(GridView1.Rows中的GridViewRow行)
// {
// string columnData = row.Cells [columnIndex] .Text;
// if(!(string.IsNullOrEmpty(columnData)| | c olumnData == ))
// {
// notAvailable = false;
// GridView1.HeaderRow.Cells [ columnIndex] .Visible = true;
// break;
//}
//}
// if(notAvailable)
// {
// //隐藏目标标题单元格
/ / GridView1.HeaderRow.Cells [columnIndex] .Visible = false;
// //;
// //隐藏目标每行的单元格
// foreach(GridView1.Rows中的GridViewRow行)
// row.Cells [columnIndex] .Visible = false;
//}
// columnIndex ++;
//}
//}
/protected void GridView1_RowDataBound(object sender,GridViewRowEventArgs e)
//{
// // Make sure there are at least header row
// if (GridView1.HeaderRow != null)
// {
// int columnIndex = 0;
// // For each column
// foreach (DataControlFieldCell clm in GridView1.HeaderRow.Cells)
// {
// bool notAvailable = true;
// // For each row
// foreach (GridViewRow row in GridView1.Rows)
// {
// string columnData = row.Cells[columnIndex].Text;
// if (!(string.IsNullOrEmpty(columnData) || columnData == " "))
// {
// notAvailable = false;
// GridView1.HeaderRow.Cells[columnIndex].Visible = true;
// break;
// }
// }
// if (notAvailable)
// {
// // Hide the target header cell
// GridView1.HeaderRow.Cells[columnIndex].Visible = false;
// // ;
// // Hide the target cell of each row
// foreach (GridViewRow row in GridView1.Rows)
// row.Cells[columnIndex].Visible = false;
// }
// columnIndex++;
// }
// }
这篇关于如何隐藏gridview中具有空值的列。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文