GridView中的数据集列隐藏 [英] Dataset column hidding in GridView

查看:129
本文介绍了GridView中的数据集列隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
正在使用GridView,并且在将数据集绑定到网格的同时,我将列映射设置为MappingType.Hidden,用于少数列,但是Gridview显示了所有列.
不知道是什么问题.如果有人在这里告诉我有关问题,请.

代码

Hi All,
am working with GridView and while binding dataset to grid i am setting column mapping to MappingType.Hidden for few columns but Gridview is showing all.
am not sure what is the issue. please if anyone tell me about the issue here.

code

oDs.Tables(0).Columns("id").ColumnMapping = MappingType.Hidden
GridView1.DataSource = oDs
GridView1.DataBind()



我没有设计itemTemplate,因为网格位于母版页上,并且多个页面正在将Distict数据集传递给它.因此不能将列设置为visible = false.



i am not designing itemTemplate because grid is on master page and multiple pages are passing distict datasets to it. so can''t set columns to visible = false.

推荐答案

请尝试这样.希望对您有帮助.
Please try like this. Hope this will help you.
foreach (DataColumn dc in oDs.Tables(0).Columns)
            {
                BoundColumn dgc = new BoundColumn();
                dgc.HeaderText = dc.ColumnName;
                dgc.DataField = dc.ColumnName;
                if (dc.ColumnName.Contains("Id"))
                    dgc.Visible = false;
                GridView1.Columns.Add(dgc);
            }


Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated


        For Each col As DataColumn In CType(GridView1.DataSource, _
                                            DataSet).Tables(0).Columns
        If col.ColumnMapping = MappingType.Hidden Then
                e.Row.Cells(CType(GridView1.DataSource, _
                            DataSet).Tables(0).Columns.IndexOf(col.ColumnName) + 1)
                            .Visible = False
        End If
        Next
End Sub


使用"GridView_RowDataBound"事件.
Use "GridView_RowDataBound" Event.
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
    e.Row.Cells[index].Visible = false;
}



放置要隐藏的列的索引.



Put the index of column you want to hide.


这篇关于GridView中的数据集列隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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