本文介绍了如何使用colums.visible方法隐藏gridview中的列[已解决]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的表格中,我有15列,我只希望在网格中显示5列.
我正在使用以下方法
gridview1.datasource = dt;
gridview1.databound();
gridview1.columns [1] .visible = false;

我收到索引超出范围的错误.

in my table i have 15 columns i want only 5 columns to display in grid.
i am using following method
gridview1.datasource=dt;
gridview1.databound();
gridview1.columns[1].visible=false;

i am getting the error that index out of range.

推荐答案

protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[0].Visible = false;
    }


但请看下面的代码,因为它有一个优势,这也隐藏了您提到的&您可以在运行时从该第一列获取值.所以我更喜欢你.


but take a look at the below code, because it have an advantage, also this hides the column you mentioned & you can get the value from that 1st column at run time. so i prefer this for you.

protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[1].Attributes.Add("style", "display:none");
    }


这篇关于如何使用colums.visible方法隐藏gridview中的列[已解决]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 04:21