Following function adds column number at first row in your datatable.
public static void AddColumnNumberInGrid(DataSet
ds, int startColumnIndex)
{
object[] cols = new object[ds.Tables[0].Columns.Count];
for (int i = 0; i
< cols.Length; i++)
{
if (i >= startColumnIndex)
{
cols[i] = (i + 1 - startColumnIndex).ToString();
}
else
{
//cols[i] = String.Empty;
}
}
DataRow row = ds.Tables[0].NewRow();
row.ItemArray = cols;
ds.Tables[0].Rows.InsertAt(row, 0);
ds.AcceptChanges();
}
No comments:
Post a Comment