如何隐藏与自动生成的列一个ASP.NET的GridView列? [英] How to hide columns in an ASP.NET GridView with auto-generated columns?

查看:615
本文介绍了如何隐藏与自动生成的列一个ASP.NET的GridView列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GridView1.Columns.Count始终为零甚至SqlDataSource1.DataBind();

GridView1.Columns.Count is always zero even SqlDataSource1.DataBind();

但电网是确定

我可以做

for (int i = 0; i < GridView1.HeaderRow.Cells.Count;i++)

我在这里重新命名请求头

I rename request headers here but

GridView1.Columns[i].Visible = false;

由于GridView1.Columns.Count是0,我不能使用它。

I can't use it because of GridView1.Columns.Count is 0.

所以,我怎么能隐藏他们呢?

So how can I hide them ?

推荐答案

尝试把 e.Row.Cells [0] =。可见假; 中的 RowCreated 事件网格的。

Try putting the e.Row.Cells[0].Visible = false; inside the RowCreated event of your grid.

protected void bla_RowCreated(object sender, GridViewRowEventArgs e)
{
    e.Row.Cells[0].Visible = false; // hides the first column
}

此方式,自动隐藏整列。

This way it auto-hides the whole column.

您没有访问生成列通过 grid.Columns [I] 在GridView的数据绑定事件。

You don't have access to the generated columns through grid.Columns[i] in your gridview's DataBound event.

这篇关于如何隐藏与自动生成的列一个ASP.NET的GridView列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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