0
Posted on 4:23 AM by prajeesh and filed under ,
Some situations it becomes necessary that the data that to be populated to a gridview or any other controls not directly come from a single function but we have to get it from some other source, like from multiple functions, a file system, or other sources. In such ssituations you can populate the DataSet or DataTable in your ASP.NET web page programmatically and then bind the web control with this data object.
Here i would like to explain a simple method to achieve this
DataTable dtHome = new DataTable();
dtHome.Columns.Add("Name",string.Empty.GetType());
dtHome.Columns.Add("City",string.Empty.GetType());
dtHome.Columns.Add("State",string.Empty.GetType());

Now we have successfully created a data table with empty rows with string data type fields, in next step we have to add rows in the data table.
dtHome.Rows.Add("Prajeesh","Calicut","Kerala");
Now we have added a single row to the data table, you can use this datatable to populate a grid view or other data presentation controls, it will display a single row of data.
GridView1.DataSource = dtHome;
GridView1.DataBind();

Shout it kick it on DotNetKicks.com
0
Responses to ... Creating data table dynamically using asp net