Click here to Skip to main content
15,358,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<asp:TemplateField HeaderText="Departure Date" meta:resourcekey="TemplateFieldResource7"   >
                           <asp:Repeater ID="repSector" runat="server" DataSource='<%# CType(Container.DataItem,System.Data.DataRowView).Row.GetChildRows("Booking_Part_TO_Sector_FK") %>'>
                                   <asp:Label ID="Label6" SortExpression ="DepartureDateTime" CssClass="block" Text='<%# String.Format( "{0:dd-MMM-yyyy}", DataBinder.Eval(Container.DataItem, "(dep_datetime)") ) %>'
                                       runat="server" meta:resourcekey="Label6ResourceKey" />
                       <ItemStyle Font-Bold="False" Width="8em" />
Member 11491784 18-Jun-15 3:58am
I want to sort data according to DepartureDate time and arrival date time, but i dont know how to do this at the time of Databind
Andy Lanng 18-Jun-15 4:39am
You can to it before databind. Why do you have to do it at the time of databind?
Member 11491784 18-Jun-15 6:10am
What do you mean by before, it is coming from database and populating the labels
Dev O'Connor 18-Jun-15 6:11am
What format is your Data Source in? Dataset? DataTable? SQL/ODBC DataReader?
Member 11491784 18-Jun-15 6:12am
Dim ReturnedDataSet As New DataSet
Member 11491784 18-Jun-15 6:12am
Dim ReturnedDataSet As New DataSet
Dev O'Connor 18-Jun-15 6:12am
Ok give me a mo
Dev O'Connor 18-Jun-15 12:23pm
Please mark the answer as the solution if this has resolved your question.

Thank you

1 solution


you really should do this when selecting the data originally however if this is not achieveable you can use the following

Solution 1 - Better solution causes less overhead and lets SQL provider/server do the work.
Dim strSQL as string = "SELECT * FROM TravelData ORDER BY DepartureDate ASC, ArrivalDate ASC"

Solution 2:
Private Sub GrabData()
    'Your Data Set
    Dim ReturnedDataSet As New DataSet

    '   Perform population here of your dataset

    'Perform The Sort
    Dim tmpDataView As New DataView(ReturnedDataSet.Tables(0)) With {.Sort = "DepartureDate ASC, ArriveDate ASC"}

    'Remove Original and Add
    ReturnedDataSet.Tables.Remove(0) : ReturnedDataSet.Tables.Add(tmpDataView.ToTable)

    MyDataGrid.DataSource = ReturnedDataSet

End Sub

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