隐藏名字的GridView列在ASP.Net运行 [英] Hide a GridView column by name at runtime in ASP.Net

查看:133
本文介绍了隐藏名字的GridView列在ASP.Net运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以显示/按名称隐藏在运行时的GridView列

Is it possible to show/hide a GridView column at runtime by name?

我可以通过类似如下的指标做到这一点:

I can do it via the index like the following:

gridReviews.Columns[4].Visible = false;



不过,我想做到以下几点:

However I'd like to do the following:

gridReviews.Columns["Name"].Visible = false;



什么是做到这一点的最好方法是什么?

What's the best way to do this?

推荐答案

您可以使用下面的代码吧:

You can use the following code for it:

foreach (DataControlField col in gridReviews.Columns)
        {
            if (col.HeaderText == "Name")
            {
                col.Visible = false;
            }
        }

这篇关于隐藏名字的GridView列在ASP.Net运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆