How to hide gridview column after databind?

你。 提交于 2019-12-03 22:15:44

Try this,

grid1.Columns[columnIndex].Visible= false;

Edit based on comment of questioner, for getting values of hidden columns

You can use hidden fields to store column wise values. This article has example that will help how to use hidden fields.

Instead of hiding column you can put the data of columns in datakeynames and later access those values. This will be useful in grabbing how to use DataKeyNames. By this method you may need to pass the id from data key names and get the record.

Fernando Pinto

try this example, (i don't speak english)

into RowDataBound ...

 protected void gvTeste_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            teste listaTeste = e.Row.DataItem as ListaTeste;

            if (listaTeste.ID == 0)
            {
                e.Row.Cells[2].Text = "Não Atribuido";
            }

            if (e.Row.Cells[7].Text == "01/01/0001" || e.Row.Cells[8].Text == "01/01/0001")
            {
                **e.Row.Visible = false;** // disable row
            }
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!