• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

ASP.NET Datagrid

azuro

n00b
Joined
Dec 14, 2002
Messages
62
Hi everyone, here's my situation. I would like to export the datagrid to Excel. However, I want to remove some of the columns from the datagrid before export it to excel. How can I remove those unwanted columns? Thanks for your help.
 
im not sure how you are exporting it but here is a link to delete a column from a data grid web control. Also you didnt state your language.


http://www.pardesifashions.com/Softomatix/RemoveGridColumn.aspx


How to remove DataGrid column
This is one of the most frequently asked question by developers who are using DataGrid control for displaying data. A lot of experts have suggested different approaches. So we decided to do alittle research on this. And to our surprise, the solution could not have been that simple.

The key to the solution is capturing ItemDataBound event. When the page recieves this event, complete information about the data row is available in DataGridItemEventArgs parameter of the event handler. Item property of this parameter contains information about the table rows and cells that will get rendered on the page. This is where you can take of the cells that you want to or do not wantt o show. The only caveat is that you should know the index of the column that you want to remove. The following code snippet shows how you can get rid of first column from the grid.
Code:
private void OnDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
	e.Item.Cells.Remove(e.Item.Cells[0]);
}
 
Back
Top