Wednesday, April 20, 2011

Add Row / Columns to GridView (Programmatically)


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 objects
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] = “First”;
row1 [SecondC] =”Second”
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();
And you have successfully added rows/cols to the grid !

Monday, April 18, 2011

Monday, June 9, 2008

EURO 08 Day2

PODOLSKI SHOW !!
Yesterday the world witnessed the charisma of the german boy . Critics had written him off saying that with Klose being fit and in form after the last world cup, Podolski proved himself!!

This is my first blog..........
Please bear with me.....
Coz I'm sure there is more to come !!