Monday, 8 March 2010

Dynamic Columns

DataTable dtbl1 = new DataTable();
dtbl1=c1.FetchRecords("items");

dngrview.DataSource = null;
dngrview.DataBind();
DataTable dt = new DataTable();
for (int i = 0; i <= dtbl1.Rows.Count-1; i++)
{
DataColumn dc = new DataColumn(dtbl1.Rows[i]["ItemName"].ToString() , typeof(System.Int32));
dt.Columns.Add(dc);

}

DataRow dr = dt.NewRow();
dt.Rows.Add(dr);

dngrview.DataSource = dt;
dngrview.DataBind();