0
Hi,
In xxxx.xaml.cs,
1) Create a DataTable object to which than we will bind the GridView
DataTable dt=new DataTable();
2) IF you need two columns than create two DataColumn object
DataColumn dCol1=new DataColumn(FirstC, typeof(System.String)); // string FirstC="column1?
DataColumn dCol2=new DataColumn(SecondC, typeof(System.String)); // string SecondC="column2?
Add it to the table
dt.Columns.Add(dCol1);
dt.Columns.Add(dCol2);
3)Run the loop for as many rows you want to add.
// say you want to add two rows
for(int i=0;i<2;i++)
{
DataRow row1 = dt.NewRow();
row1 [FirstC] = "One";
row1 [SecondC] ="Two"
dt.Rows.Add(row1 );
}
Now iterate through each datacolumn and create a BoundField foreach column
foreach (DataColumn col in dt.Columns)
{
BoundField bField = new BoundField
bField.DataField = col.ColumnName;
bField.HeaderText = col.ColumnName;
GridView1.Columns.Add(bField);
}
GridView1.DataSource = dt;
//Bind the datatable with the GridView.
GridView1.DataBind();