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

查看:23
本文介绍了如何使用自动生成的列隐藏 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].Visible = false; 放入 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.

您无法通过 gridview 的 DataBound 事件中的 grid.Columns[i] 访问生成的列.

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天全站免登陆