Click here to Skip to main content
16,020,669 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody,

I am a new ASP.NET developer and I want to create a table programmatically using HtmlTable or DataTable and then filling this table with the data from the database using DataView.

I could be able to create a table using HtmlTable but when I did a search regarding "how to fill HtmlTable with a data using DataView", I found that DataView will not work with HtmlTable. So I repeated creating the table using the DataTable, but now I need to fill it with the data using DataView, so how can I do that?

My code:
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();
Posted
Updated 23-Dec-11 7:48am
v2
Comments
Sandeep Mewara 23-Dec-11 13:40pm    
Why Dataview? Reason? Not clear on what are you trying to achieve here.

 
Share this answer
 
 
Share this answer
 
Comments
NandaKumer 24-Dec-11 19:48pm    
good link
Monjurul Habib 25-Dec-11 2:17am    
thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900