删除Gridview上的列 [英] Remove columns on Gridview

查看:102
本文介绍了删除Gridview上的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有10列的Gridview。我有一个条件,我需要

隐藏其中的5个,但我不知道如何隐藏列。我可以在行数据绑定事件中隐藏一个单元格确定

但不是如何隐藏整列(我假设在数据绑定之前是
)。谢谢。


David

解决方案

" David C" < dl ***** @ lifetimeinc.comwrote in message

news:%2 **************** @ TK2MSFTNGP03.phx.gbl .. 。


>我有一个有10列的Gridview。我有一个条件,我需要隐藏其中的5个,但我不知道如何隐藏列。我可以在行数据绑定事件中隐藏单元格确定
但不是如何隐藏整列(我假设在数据绑定之前)。谢谢。



MyGridView.Columns [n] .Visible = false;


取决于。如果你想访问列中的数据,最好使用CSS将
隐藏起来。设置可见属性导致单元格不会被渲染为



在代码隐藏中:


protected void GridView1_RowCreated(object sender,

GridViewRowEventArgs e)

{

if(e.Row.RowType!= DataControlRowType.Pager)

{

//隐藏不需要的列

e.Row.Cells [0] .CssClass =" hidden";

e.Row.Cells [1] .CssClass =" hidden";

}

}


和CSS上课简单:


..隐藏

{

显示:无;

}


HTH ...

4月2日下午2:27,David C < dlch ... @ lifetimeinc.comwrote:


我有一个有10列的Gridview。我有一个条件,我需要

隐藏其中的5个,但我不知道如何隐藏列。我可以在行数据绑定事件中隐藏一个单元格确定

但不是如何隐藏整列(我假设在数据绑定之前是
)。谢谢。


David



Mark,

我需要在其中一个GridView事件中执行此操作,如果是这样的话?

谢谢。


David

" Mark Rae < ma ** @ markNOSPAMrae.com写信息

新闻:或************** @ TK2MSFTNGP04.phx.gbl ...
< blockquote class =post_quotes>
" David C" < dl ***** @ lifetimeinc.comwrote in message

news:%2 **************** @ TK2MSFTNGP03.phx.gbl .. 。


>>我有一个有10列的Gridview。我有一个条件,我需要隐藏其中的5个,但我不知道如何隐藏列。我可以在行数据绑定事件中隐藏一个单元格确定但不是如何隐藏整列(我在数据绑定之前假设)。谢谢。



MyGridView.Columns [n] .Visible = false;



I have a Gridview that has 10 columns. I have a condition where I need to
hide 5 of them but I''m not sure how to hide a column. I can hide a cell ok
in the row databound event but not sur how to hide whole columns (I assume
before databound). Thanks.

David

解决方案

"David C" <dl*****@lifetimeinc.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...

>I have a Gridview that has 10 columns. I have a condition where I need to
hide 5 of them but I''m not sure how to hide a column. I can hide a cell ok
in the row databound event but not sur how to hide whole columns (I assume
before databound). Thanks.

MyGridView.Columns[n].Visible = false;


Depends. If you want access to the data in the column, it''s best to
hide it using CSS. Setting the "Visible" property causes the cells not
to be rendered at all.

In the code-behind:

protected void GridView1_RowCreated(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType != DataControlRowType.Pager)
{
// hide unwanted columns
e.Row.Cells[0].CssClass = "hidden";
e.Row.Cells[1].CssClass = "hidden";
}
}

And the CSS class is simply:

..hidden
{
display: none;
}

HTH...
On Apr 2, 2:27 pm, "David C" <dlch...@lifetimeinc.comwrote:

I have a Gridview that has 10 columns. I have a condition where I need to
hide 5 of them but I''m not sure how to hide a column. I can hide a cell ok
in the row databound event but not sur how to hide whole columns (I assume
before databound). Thanks.

David



Mark,
Do I need to do this in one of the GridView events, and if so which one?
Thanks.

David
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:OR**************@TK2MSFTNGP04.phx.gbl...

"David C" <dl*****@lifetimeinc.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...

>>I have a Gridview that has 10 columns. I have a condition where I need to
hide 5 of them but I''m not sure how to hide a column. I can hide a cell
ok in the row databound event but not sur how to hide whole columns (I
assume before databound). Thanks.


MyGridView.Columns[n].Visible = false;



这篇关于删除Gridview上的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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