使用微软的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 == " " 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 == " " select item).ToList().Count; if (TotalNullRecords == RadGrid1.MasterTableView.Items.Count) { column.Visible = false; } } }更多推荐
如果所有行的数据为空隐藏列
发布评论