我们对表使用什么属性?就像我们在gridview中使用数据源 [英] What property do we use for table ? like we use Datasource in gridview

查看:74
本文介绍了我们对表使用什么属性?就像我们在gridview中使用数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张桌子,但没有gridview.我想从数据库中检索数据并填写表格.我知道对于gridview我们使用数据源.我们用什么来代替桌子?由于该表没有数据源属性.

DataSet ds = new DataSet();
GridView1.DataSource = ds;
GridView1.DataBind();

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();

推荐答案

这将向您展示如何向数据表添加数据. 这是链接(C#中的DataTable) [
This will show you how you can add data to a datatable.
Here is the link (DataTable In C#)[^]

-OR-

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


为此,您可以尝试使用Repeater控制.这将帮助您设计动态表.

For this, You can try Repeater control. This will help you to design dynamic table.

<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.

DataSet mycdcatalog = GetCatalogDataSetByID(CatalogId);
cdcatalog.DataSource=mycdcatalog;
cdcatalog.DataBind();


这篇关于我们对表使用什么属性?就像我们在gridview中使用数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆