I am a new ASP.NET developer, and I want to create a table programmatically using HtmlTable or DataTable , and then populating this table with data from the database using DataView .
I could create a table using HtmlTable , but when I did a search regarding "how to populate an HtmlTable with data using a DataView ", I found that the DataView would not work with an HtmlTable . So I repeated the creation of the table using the DataTable , but now I need to populate it with data using the DataView , so how can I do this?
My code is:
DataTable table = new DataTable(); DataColumn col1 = new DataColumn("Name"); DataColumn col2 = new DataColumn("Username"); col1.DataType = System.Type.GetType("System.String"); col2.DataType = System.Type.GetType("System.String"); table.Columns.Add(col1); table.Columns.Add(col2); DataRow row = table.NewRow(); row[col1] = "John"; row[col2] = "John123"; table.Rows.Add(row); GridView gv = new GridView(); gv.DataSource = table; gv.DataBind();
Regarding the table in the database, the schema of the user table:
Username, FirstName, LastName, Age, Job
source share