Click here to Skip to main content
15,900,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm having a table but not a gridview. I want to retrieve the data from the database and fill in the table . I know for the gridview we use datasource. what do we use for the table instead? since the table does not have datasource property.

DataSet ds = new DataSet();
GridView1.DataSource = ds;
GridView1.DataBind();
Posted
Updated 20-Dec-11 11:24am
v2
Comments
[no name] 21-Dec-11 1:23am    
it is DataTable or HTML Table?

This will show you how you can add data to a datatable.
Here is the link (DataTable In C#)[^]

-OR-

C#
OleDbConnection MyOleDbConnection = new OleDbConnection("[YourConnectionString]"));
OleDbDataAdapter MyOleDbDataAdapter = new OleDbDataAdapter();
MyOleDbDataAdapter.SelectCommand = new OleDbCommand("SELECT [Column] FROM [Table]", MyOleDbConnection);

DataTable myDataTable = new DataTable();

MyOleDbConnection.Open();
try
{
  MyOleDbDataAdapter.Fill(myDataTable);
}
finally
{
  MyOleDbConnection. Close();
}


Good luck
 
Share this answer
 
v2
For this, You can try Repeater control. This will help you to design dynamic table.

C#
<asp:repeater id="cdcatalog" runat="server" xmlns:asp="#unknown">

<HeaderTemplate>
<table border="1" width="100%">
<tr>
<th>Title</th>
<th>Artist</th>
<th>Country</th>
<th>Company</th>
<th>Price</th>
<th>Year</th>
</tr>
</HeaderTemplate>

<itemtemplate>
<table><tbody><tr>
<td><![CDATA[<%#Container.DataItem("title")%>]]></td>
<td><![CDATA[<%#Container.DataItem("artist")%>]]></td>
<td><![CDATA[<%#Container.DataItem("country")%>]]></td>
<td><![CDATA[<%#Container.DataItem("company")%>]]></td>
<td><![CDATA[<%#Container.DataItem("price")%>]]></td>
<td><![CDATA[<%#Container.DataItem("year")%>]]></td>
</tr></tbody></table>
</itemtemplate>

<footertemplate>
</footertemplate></table>


</asp:repeater>


and in Code behind you can use binding a dataset to repeater control.

C#
DataSet mycdcatalog = GetCatalogDataSetByID(CatalogId);
cdcatalog.DataSource=mycdcatalog;
cdcatalog.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