Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 6-Mar-12 5:34am
v4
Comments
Herman<T>.Instance 6-Mar-12 10:21am    
show your code

1 solution

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