Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Dear All

Could anyone please tell me how to show data from an Asp Table to a GridView in asp .Net


Thank You
Posted
Comments
Nirav Prabtani 3-Jun-14 2:46am    
What do you mean by ASP table>>
SubhashRokzzz 3-Jun-14 2:48am    
A simple table.
I declared It as
<asp:Table id="Table1" runat="server">

after that I filled this Table1 with values. Now I want this Table1 values display in a gridview
Karthik_Mahalingam 3-Jun-14 2:50am    
Please add more information to the question. by "Improve question".
note that Gridview will render as a HTML table in the web browser.
BTW why u need to display the Table in GRID ???
SubhashRokzzz 3-Jun-14 2:54am    
Could you please tell me how to copy data from a Table(it is not a database table ) to DataTable in asp .Net?
DamithSL 3-Jun-14 3:10am    
how you fill this asp Table? can you update the question with the code?

1 solution

HTML code
ASP.NET
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="false" xmlns:asp="#unknown">
    <columns>
        <asp:boundfield datafield="Id" headertext="Id" />
        <asp:boundfield datafield="Name" headertext="Name" />
        
    </columns>
</asp:gridview>

C#
C# Code

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        DataTable dt = new DataTable();
        dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
                            new DataColumn("Name", typeof(string))});
        dt.Rows.Add(1, "Ramesh","India");
        dt.Rows.Add(2, "Suresh","India");
        
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
}
 
Share this answer
 

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