ASP数据列表以与数据集不同的顺序显示数据 [英] ASP Datalist is displaying data in a different order to the DataSet

查看:47
本文介绍了ASP数据列表以与数据集不同的顺序显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是ASP的新手,对我的DataList显示按字母顺序排序的DataSet中的数据的方式有些困惑.

我已经从数据库中检索了我的DataSet,并逐行浏览数据,但是我的DataList是以随机方式显示数据的,即显示的数据似乎没有任何顺序.

如何确保DataList以与我的DataSet相同的顺序显示数据?

如果有帮助.这是将我的DataSet绑定到我的DataList的代码.

< pre lang ="c#">
OleDbConnection pageConnection =新的OleDbConnection(@"provider = Microsoft.ace.Oledb.12.0;数据源= C:\ Projects \ MyDatabase.accdb; Persist Security Info = False");

OleDbDataAdapter listCommand =新的OleDbDataAdapter("select * from Table",pageConnection);
DataSet listDS = new DataSet();

//创建并填充数据集.
listCommand.Fill(listDS);

DataList1.DataSource = listDS;
DataList1.DataBind();
</pre>

< pre lang ="HTML">
< asp:DataList ID ="DataList1" runat ="server" Style ="position:absolute; top:255px; left:265px; height:397px; width:500px; margin-top:0px;" RepeatColumns ="2">
< HeaderTemplate>
< table width ="100%">
< tr align ="left">
< th>
参数
</th>
< th>

</th>
</tr>
</table>
</HeaderTemplate>
< ItemTemplate>
< tr align ="left">
< td>
<%#DataBinder.Eval(Container.DataItem,"Parameter")%>
</td>
< td>
<%#DataBinder.Eval(Container.DataItem,"Value")%>
</td>
</tr>
< div style ="padding:15,15,15,15; font-size:10pt; font-family:Verdana">
</div>
</ItemTemplate>
</asp:DataList>
</pre>

TIA

Tony

Hi,

I''m new to ASP and am somewhat confused about the way my DataList is displaying the data from an alphabetically sorted DataSet.

I have retrieved my DataSet from my database, and stepped through the data row by row, but my DataList is displaying the data in a random manner, i.e. there doesn''t appear to be any order to the data displayed.

How can I ensure that the DataList displays the data in the same order as my DataSet is ordered?

If it will help. here is my code that binds my DataSet to my DataList

<pre lang="c#">
OleDbConnection pageConnection = new OleDbConnection(@" provider=Microsoft.ace.Oledb.12.0; data source=C:\Projects\MyDatabase.accdb;Persist Security Info=False");

OleDbDataAdapter listCommand = new OleDbDataAdapter("select * from Table", pageConnection);
DataSet listDS = new DataSet();

// Create and fill a DataSet.
listCommand.Fill(listDS);

DataList1.DataSource = listDS;
DataList1.DataBind();
</pre>

<pre lang="HTML">
<asp:DataList ID="DataList1" runat="server" Style="position:absolute; top: 255px; left: 265px; height: 397px; width: 500px; margin-top: 0px;" RepeatColumns="2" >
<HeaderTemplate>
<table width="100%">
<tr align="left">
<th>
Parameter
</th>
<th>
Value
</th>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<tr align="left">
<td>
<%# DataBinder.Eval(Container.DataItem, "Parameter") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "Value") %>
</td>
</tr>
<div style="padding:15,15,15,15;font-size:10pt; font-family:Verdana">
</div>
</ItemTemplate>
</asp:DataList>
</pre>

TIA

Tony

推荐答案

将以与数据源相同的顺序填充数据列表,它不会自行进行任何排序.从您的代码中,我不会在哪里强制填充DateSet,但请确保其中没有多个DataTables.如果只需要一个DataTable,则使用它,而不是DataSet.
The DataList will be populated in the same order as the DataSource, it doesn''t do any sorting on its own. From you code I don''t where you are actully populating the DateSet but make sure there are not multiple DataTables in it. If you only need one DataTable then use it, not a DataSet.


这篇关于ASP数据列表以与数据集不同的顺序显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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