Royson
Royson

Reputation: 2901

Deleting columns with rows values from data table

I want to delete specific column from my datable before bounding it to a grid view. I tried with

finalTable.Columns.RemoveAt(0);
finalTable.Columns.RemoveAt(1);

but it does not delete rows values belonging to that column..

How can we delete column with row values??

EDIT: After bounding it to gridview rows are displayed in 3rd column.

Upvotes: 2

Views: 1547

Answers (2)

THE DOCTOR
THE DOCTOR

Reputation: 4555

give this a try:

 DataTable example; 
       example.Columns.Remove("columnName"); 
       example.Columns.RemoveAt(columnIndex); 

Upvotes: 1

Amsakanna
Amsakanna

Reputation: 12934

Try this:

If(finalTable.Columns.CanRemove(finalTable.Columns[0]))
{
    finalTable.Columns.RemoveAt(0); 
}

finalTable.AcceptChanges()

Then bind it with your gridview

Upvotes: 0

Related Questions