如何让几个GridView的列看不见的动态? [英] How do I make several gridview columns invisible dynamically?

查看:147
本文介绍了如何让几个GridView的列看不见的动态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用

e.Row.Cells[0].Visible = false;

使一列不可见。它的工作原理,但是当我尝试添加另一个像这样:

to make a single column invisible. It works but when I try to add another like so:

e.Row.Cells[0].Visible = false; 
e.Row.Cells[1].Visible = false; //i tried listing all and still got the out of range error 

我得到的错误指定的参数已超出有效值的范围。
参数名称:索引

我使用GridView的的RowDataBound 事件的命令,并从0开始GridView的有12列

I am using the commands in the Gridview's RowDataBound Event and starting from 0 the gridview has 12 columns

推荐答案

要考虑到一个 GridView控件有一些行不属于数据(寻呼机,页脚等)

Take into account that a GridView has some rows that are not data (pager, footer, etc).

我说你应该有这样的事情,所以你只适用隐藏的逻辑的DataRow 元素。

I'd say you should have something like this so you only apply hiding logic to DataRow elements.

if (e.Row.RowType == DataControlRowType.DataRow)
{
    e.Row.Cells[0].Visible = false; 
    e.Row.Cells[1].Visible = false;
}

要查看所有行类型检查这个MSDN文章

To see all row types check this MSDN article.

这篇关于如何让几个GridView的列看不见的动态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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