Bibek Aryal Bibek Aryal - 1 year ago 73
ASP.NET (C#) Question

Remove the first column from datatable

I am using Datatable to get some values from a database table.

DataTable dt = this.GetData();
StringBuilder html = new StringBuilder();
html.Append("<table border = '1'>");
foreach (DataRow row in dt.Rows)
foreach (DataColumn column in dt.Columns)

The above code gives me this output:
enter image description here
The column with 0 0 is generated from the ID column of my table. I didn't pass the ID through my Stored Procedure because I dont need to display them. Is there a way to remove the first column itself and prevent it from displaying?

Answer Source

you can also use FOR instead of FOREACH and start from 1 instead of 0

for(int i=1;i<dt.Columns.Count;i++){//do whatever}