get index of DataTable column with name get index of DataTable column with name asp.net asp.net

get index of DataTable column with name


You can use DataColumn.Ordinal to get the index of the column in the DataTable. So if you need the next column as mentioned use Column.Ordinal + 1:

row[row.Table.Columns["ColumnName"].Ordinal + 1] = someOtherValue;


Try this:

int index = row.Table.Columns["ColumnName"].Ordinal;


You can simply use DataColumnCollection.IndexOf

So that you can get the index of the required column by name then use it with your row:

row[dt.Columns.IndexOf("ColumnName")] = columnValue;