Remove a column from the gridview

0

I am implementing a feature in a project using ASP.NET MVC and I'm trying to remove some columns from a gridview that I created in my application, the gridview datasource is a table in the database, however I want to remove some columns from the table , since I am trying to export this data to an excel file and some table items as the primary key are not required. How do I remove columns from my choice of gridview? I've tried things like:

gv.Columns.Remove("ArquivoExcelId");

I also tried:

gv.Columns[0].Visible = false;

But the 2 generated error, as if the past parameters were incompatible or something, does anyone know how to do this?

    
asked by anonymous 21.12.2015 / 18:09

2 answers

0

Friend, why do not you filter the column by removing it from select ?

You can also make the change via front-end, by css by putting style = "display: none;" in the column.

Another solution via server side is to mount the columns through RowDataBound . If you prefer, treat the DataSet:

gv.Columns.RemoveAt(0); //Index da coluna 'ArquivoExcelId'

Or

gv.Columns.Remove("ArquivoExcelId");

    
22.12.2015 / 19:47
0

Try this:

private void BindDataAndInitializeColumns()
{
    dataGridView1.AutoGenerateColumns = true;
    dataGridView1.DataSource = customersDataSet;
    dataGridView1.Columns.Remove("Fax");
    dataGridView1.Columns["CustomerID"].Visible = false;
}

Taken from MSDN.

Or with gv.Columns.RemoveAt(x) ;

    
22.12.2015 / 14:07