Hide a GridView column by name at runtime in ASP.Net

半世苍凉 提交于 2019-12-04 22:35:33

You can use the following code for it:

foreach (DataControlField col in gridReviews.Columns)
        {
            if (col.HeaderText == "Name")
            {
                col.Visible = false;
            }
        }

You can access the gridview by column name indirectly if you can access the data you used to bind the gridview and the gridview columns are in the same order as the datatable (and AutoGenerateColumns = false):

//Make ID column invisible by column name
gv.Columns[dt.Columns[ID].Ordinal].Visible = false;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!