如果所有行的数据为空隐藏列

编程入门 行业动态 更新时间:2024-10-26 07:25:40
本文介绍了如果所有行的数据为空隐藏列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用微软的Visual Studio 2012中,Telerik的,C#.ASP.NET。

Using MS Visual Studio 2012, Telerik, C#.ASP.NET.

我需要的逻辑如下:

If a columns data on all rows is null then hide the column

基本上,如果列3行数据,如果所有null,则不要打扰显示此列,但是如果在他们的值为1,则表明该列。

Basically if a column has 3 rows of data, if there all null then dont bother displaying that column, however if there is a value in 1 of them, then show the column.

被玩弄:

foreach (GridColumn columns in dgvUserResults.Columns) { if (columns != null) { columns.Visible = false; } else { columns.Visible = true; } }

code不会通过foreach循环过程中犯规迭代的工作只是跳过它。虽然不在意,即使它没有遍历我需要一种方法来检查是否所有列[名]行是空的。有一个漂亮的Telerik的单行?

code doesn't work of course doesnt iterate through the foreach loop just skips it. Although not bothered about that even if it did iterate through I need a way to check if all column[name] rows are null. There a nice Telerik one liner?

推荐答案

请与尝试以下code片段。

Please try with below code snippet.

使用UniqueName

Using UniqueName

protected void RadGrid1_PreRender(object sender, EventArgs e) { foreach (GridColumn column in RadGrid1.MasterTableView.Columns) { // If you used ClientSelectColumn then below code is not worked For that you have to put condition //if(column.ColumnType == "GridBoundColumn") int TotalNullRecords = (from item in RadGrid1.MasterTableView.Items.Cast<GridDataItem>() where string.IsNullOrWhiteSpace(item[column.UniqueName].Text) || item[column.UniqueName].Text == "&nbsp;" select item).ToList().Count; if (TotalNullRecords == RadGrid1.MasterTableView.Items.Count) { RadGrid1.MasterTableView.Columns.FindByUniqueName(column.UniqueName).Visible = false; } } }

使用指数

protected void RadGrid1_PreRender(object sender, EventArgs e) { foreach (GridColumn column in RadGrid1.MasterTableView.Columns) { // If you used ClientSelectColumn then below code is not worked For that you have to put condition //if(column.ColumnType == "GridBoundColumn") int TotalNullRecords = (from item in RadGrid1.MasterTableView.Items.Cast<GridDataItem>() where string.IsNullOrWhiteSpace(item[column.UniqueName].Text) || item[column.UniqueName].Text == "&nbsp;" select item).ToList().Count; if (TotalNullRecords == RadGrid1.MasterTableView.Items.Count) { column.Visible = false; } } }

更多推荐

如果所有行的数据为空隐藏列

本文发布于:2023-11-11 10:21:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1578149.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:为空   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!