Click here to Skip to main content
15,881,753 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<asp:TemplateField HeaderText="Departure Date" meta:resourcekey="TemplateFieldResource7"   >
                       <ItemTemplate>
                           <asp:Repeater ID="repSector" runat="server" DataSource='<%# CType(Container.DataItem,System.Data.DataRowView).Row.GetChildRows("Booking_Part_TO_Sector_FK") %>'>
                               <ItemTemplate>
                                   <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" />
                               </ItemTemplate>
                           </asp:Repeater>
                       </ItemTemplate>
                       <ItemStyle Font-Bold="False" Width="8em" />
                   </asp:TemplateField>
Posted
Comments
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

1 solution

Ok,

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.
VB
Dim strSQL as string = "SELECT * FROM TravelData ORDER BY DepartureDate ASC, ArrivalDate ASC"


Solution 2:
VB
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
    MyDataGrid.DataBind()


End Sub
 
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