I have an ObjectDataSource which call the BLL / DAL function to retrieve data from the database. I bind this datasource with an ASP.NET Gridview, and it's working perfectly fine, including the sorting. However, when I try to bind it to RadGrid, the column is not sorted as expected. It only sorts the data in descending order. I browsed through this forum, and found a suggestion to set the AllowNaturalSort property to false, but it's still not working. What's wrong here?
OBJECT DATASROUCE:
<asp:ObjectDataSource ID="odsSubscriptionDetails" runat="server" SelectMethod="GetReportByExpiryDate"
TypeName="BLL.Subscription.Subscription" SortParameterName="sortExpression">
<SelectParameters>
<asp:Parameter Name="startDate" Type="DateTime" />
<asp:Parameter Name="endDate" Type="DateTime" />
<asp:Parameter Name="sortExpression" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
ASP.NET GRIDVIEW:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False"
DataSourceID="odsSubscriptionDetails">
<Columns>
<asp:BoundField DataField="SubscriberName" HeaderText="UserName"
SortExpression="SubscriberName" />
<asp:BoundField DataField="SubscriptionType" HeaderText="Type"
SortExpression="SubscriptionType" />
<asp:BoundField DataField="SubscriptionPeriod" HeaderText="Period"
SortExpression="SubscriptionPeriod" />
<asp:BoundField DataField="SubscriptionFees" HeaderText="Fees"
SortExpression="SubscriptionFees" />
<asp:BoundField DataField="StartDate" DataFormatString="{0:dd/MM/yyyy}"
HeaderText="StartDate" SortExpression="StartDate" />
<asp:BoundField DataField="EndDate" HeaderText="EndDate"
SortExpression="EndDate" />
<asp:BoundField DataField="SubscriptionStatusType" HeaderText="Status"
SortExpression="SubscriptionStatusType" />
<asp:BoundField DataField="CreateDate" HeaderText="CreateDate"
SortExpression="CreateDate" />
<asp:BoundField DataField="ProcessedByName" HeaderText="ProcessedBy"
SortExpression="ProcessedByName" />
</Columns>
</asp:GridView>
RADGRID:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False"
DataSourceID="odsSubscriptionDetails" GridLines="None" Skin="Vista">
<HeaderContextMenu>
<CollapseAnimation Duration="200" Type="OutQuint" />
</HeaderContextMenu>
<MasterTableView DataSourceID="odsSubscriptionDetails" AllowNaturalSort="false">
<RowIndicatorColumn>
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="SubscriberName" HeaderText="UserName"
UniqueName="SubscriberName" SortExpression="SubscriberName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SubscriptionType"
HeaderText="Type" UniqueName="SubscriptionType"
SortExpression="SubscriptionType">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SubscriptionPeriod"
HeaderText="Period" SortExpression="SubscriptionPeriod"
UniqueName="SubscriptionPeriod">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SubscriptionFees"
HeaderText="Fees" SortExpression="SubscriptionFees"
UniqueName="SubscriptionFees" DataType="System.Int64">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="StartDate" HeaderText="StartDate"
SortExpression="StartDate" UniqueName="StartDate" DataType="System.DateTime">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="EndDate" HeaderText="EndDate"
SortExpression="EndDate" UniqueName="EndDate" DataType="System.DateTime">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SubscriptionStatusType"
HeaderText="Status" SortExpression="SubscriptionStatusType"
UniqueName="SubscriptionStatusType">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="CreateDate" DataType="System.DateTime"
HeaderText="CreateDate" SortExpression="CreateDate" UniqueName="CreateDate">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ProcessedByName"
HeaderText="ProcessedBy" SortExpression="ProcessedByName"
UniqueName="ProcessedByName">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<FilterMenu>
<CollapseAnimation Duration="200" Type="OutQuint" />
</FilterMenu>
</telerik:RadGrid>
DAL:
CLASS: Subscription
Public Overrides Function GetReportByExpiryDate(ByVal startDate As Date, ByVal endDate As Date, ByVal pageIndex As Integer, ByVal pageSize As Integer, ByVal sortParameter As String) As System.Collections.Generic.List(Of SubscriptionDetails)
Dim sortColumn As String = String.Empty
Dim sortDirection As String = String.Empty
'Call Function to get the sortColumn
sortColumn = ProcessSortParameter(sortParameter)(0)
'Call Function to get the sortDirection (ASC / DESC)
sortDirection = ProcessSortParameter(sortParameter)(1)
Using cn As New SqlConnection(Me.ConnectionString)
Dim cmd As New SqlCommand("CMS.uspSubscriptionDetails_GetInfo_ExpiryDate", cn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@StartDate", SqlDbType.SmallDateTime).Value = startDate
cmd.Parameters.Add("@EndDate", SqlDbType.SmallDateTime).Value = endDate
cmd.Parameters.Add("@PageIndex", SqlDbType.Int).Value = pageIndex
cmd.Parameters.Add("@PageSize", SqlDbType.Int).Value = pageSize
cmd.Parameters.Add("@SortParameter", SqlDbType.VarChar).Value = sortColumn
cmd.Parameters.Add("@SortDirection", SqlDbType.VarChar).Value = sortDirection
cn.Open()
Return GetSubscriptionCollectionFromReader(ExecuteReader(cmd))
End Using
End Function
OBJECT DATASROUCE:
<asp:ObjectDataSource ID="odsSubscriptionDetails" runat="server" SelectMethod="GetReportByExpiryDate"
TypeName="BLL.Subscription.Subscription" SortParameterName="sortExpression">
<SelectParameters>
<asp:Parameter Name="startDate" Type="DateTime" />
<asp:Parameter Name="endDate" Type="DateTime" />
<asp:Parameter Name="sortExpression" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
ASP.NET GRIDVIEW:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False"
DataSourceID="odsSubscriptionDetails">
<Columns>
<asp:BoundField DataField="SubscriberName" HeaderText="UserName"
SortExpression="SubscriberName" />
<asp:BoundField DataField="SubscriptionType" HeaderText="Type"
SortExpression="SubscriptionType" />
<asp:BoundField DataField="SubscriptionPeriod" HeaderText="Period"
SortExpression="SubscriptionPeriod" />
<asp:BoundField DataField="SubscriptionFees" HeaderText="Fees"
SortExpression="SubscriptionFees" />
<asp:BoundField DataField="StartDate" DataFormatString="{0:dd/MM/yyyy}"
HeaderText="StartDate" SortExpression="StartDate" />
<asp:BoundField DataField="EndDate" HeaderText="EndDate"
SortExpression="EndDate" />
<asp:BoundField DataField="SubscriptionStatusType" HeaderText="Status"
SortExpression="SubscriptionStatusType" />
<asp:BoundField DataField="CreateDate" HeaderText="CreateDate"
SortExpression="CreateDate" />
<asp:BoundField DataField="ProcessedByName" HeaderText="ProcessedBy"
SortExpression="ProcessedByName" />
</Columns>
</asp:GridView>
RADGRID:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False"
DataSourceID="odsSubscriptionDetails" GridLines="None" Skin="Vista">
<HeaderContextMenu>
<CollapseAnimation Duration="200" Type="OutQuint" />
</HeaderContextMenu>
<MasterTableView DataSourceID="odsSubscriptionDetails" AllowNaturalSort="false">
<RowIndicatorColumn>
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="SubscriberName" HeaderText="UserName"
UniqueName="SubscriberName" SortExpression="SubscriberName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SubscriptionType"
HeaderText="Type" UniqueName="SubscriptionType"
SortExpression="SubscriptionType">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SubscriptionPeriod"
HeaderText="Period" SortExpression="SubscriptionPeriod"
UniqueName="SubscriptionPeriod">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SubscriptionFees"
HeaderText="Fees" SortExpression="SubscriptionFees"
UniqueName="SubscriptionFees" DataType="System.Int64">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="StartDate" HeaderText="StartDate"
SortExpression="StartDate" UniqueName="StartDate" DataType="System.DateTime">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="EndDate" HeaderText="EndDate"
SortExpression="EndDate" UniqueName="EndDate" DataType="System.DateTime">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SubscriptionStatusType"
HeaderText="Status" SortExpression="SubscriptionStatusType"
UniqueName="SubscriptionStatusType">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="CreateDate" DataType="System.DateTime"
HeaderText="CreateDate" SortExpression="CreateDate" UniqueName="CreateDate">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ProcessedByName"
HeaderText="ProcessedBy" SortExpression="ProcessedByName"
UniqueName="ProcessedByName">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<FilterMenu>
<CollapseAnimation Duration="200" Type="OutQuint" />
</FilterMenu>
</telerik:RadGrid>
DAL:
CLASS: Subscription
Public Overrides Function GetReportByExpiryDate(ByVal startDate As Date, ByVal endDate As Date, ByVal pageIndex As Integer, ByVal pageSize As Integer, ByVal sortParameter As String) As System.Collections.Generic.List(Of SubscriptionDetails)
Dim sortColumn As String = String.Empty
Dim sortDirection As String = String.Empty
'Call Function to get the sortColumn
sortColumn = ProcessSortParameter(sortParameter)(0)
'Call Function to get the sortDirection (ASC / DESC)
sortDirection = ProcessSortParameter(sortParameter)(1)
Using cn As New SqlConnection(Me.ConnectionString)
Dim cmd As New SqlCommand("CMS.uspSubscriptionDetails_GetInfo_ExpiryDate", cn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@StartDate", SqlDbType.SmallDateTime).Value = startDate
cmd.Parameters.Add("@EndDate", SqlDbType.SmallDateTime).Value = endDate
cmd.Parameters.Add("@PageIndex", SqlDbType.Int).Value = pageIndex
cmd.Parameters.Add("@PageSize", SqlDbType.Int).Value = pageSize
cmd.Parameters.Add("@SortParameter", SqlDbType.VarChar).Value = sortColumn
cmd.Parameters.Add("@SortDirection", SqlDbType.VarChar).Value = sortDirection
cn.Open()
Return GetSubscriptionCollectionFromReader(ExecuteReader(cmd))
End Using
End Function