Again, couldn't find anything via search so...
I have a grid that seems to be overriding the sort order that I'm specifying in the data source's SelectCommand. The table I'm trying to display has three columns; ID, Name, and DisplayOrder. ID is the primary key on the table and is a char(3) SQL data type. I am trying to sort the grid by: "DisplayOrder, Name" but no matter what I try, the grid is sorted by ID. I've tried using a stored procedure in the SelectCommand, setting the DataKeyNames to "DisplayOrder, ID", and various combinations of Grid and MasterTableView properties to no avail.
Seems simple enough, but I can't figure it out. Can someone help?
Thanks,
Jay
Grid declaration:
DataSource declaration:
I have a grid that seems to be overriding the sort order that I'm specifying in the data source's SelectCommand. The table I'm trying to display has three columns; ID, Name, and DisplayOrder. ID is the primary key on the table and is a char(3) SQL data type. I am trying to sort the grid by: "DisplayOrder, Name" but no matter what I try, the grid is sorted by ID. I've tried using a stored procedure in the SelectCommand, setting the DataKeyNames to "DisplayOrder, ID", and various combinations of Grid and MasterTableView properties to no avail.
Seems simple enough, but I can't figure it out. Can someone help?
Thanks,
Jay
Grid declaration:
<telerik:RadGrid ID="ListGrid" |
Skin="Hay" |
AllowAutomaticDeletes="True" |
AllowAutomaticInserts="True" |
AllowAutomaticUpdates="True" |
AutoGenerateColumns="false" |
DataSourceID="SQLDataSource" |
OnItemDataBound="ListGrid_ItemDataBound" |
OnItemInserted="ListGrid_ItemInserted" |
OnItemUpdated="ListGrid_ItemUpdated" |
OnItemDeleted="ListGrid_ItemDeleted" |
runat="server"> |
<ValidationSettings EnableValidation="true" /> |
<MasterTableView |
DataSourceID="SQLDataSource" |
DataKeyNames="DisplayOrder, ID" |
CommandItemDisplay="Top" |
CommandItemSettings-AddNewRecordImageUrl="~/_Images/GIF/16x16/Add.gif" |
CommandItemSettings-AddNewRecordText="Add pet type" |
CommandItemStyle-HorizontalAlign="Left" |
EditMode="InPlace" |
AutoGenerateColumns="false"> |
<SortExpressions> |
<telerik:GridSortExpression FieldName="DisplayOrder" SortOrder="Ascending" /> |
<telerik:GridSortExpression FieldName="Name" SortOrder="Ascending" /> |
</SortExpressions> |
<NoRecordsTemplate> |
<div style="padding-top:10px;padding-bottom:10px;padding-left:20px;"> |
<asp:Label ID="NoItemsLabel" |
Text="There are no items to show in this view." |
runat="server" /> |
</div> |
</NoRecordsTemplate> |
<Columns> |
<telerik:GridTemplateColumn UniqueName="LeftSpacer" |
HeaderStyle-Width="6" |
ItemStyle-Width="6"> |
<HeaderTemplate> |
|
</HeaderTemplate> |
</telerik:GridTemplateColumn> |
<telerik:GridBoundColumn UniqueName="ID" |
HeaderText="ID" |
HeaderStyle-Width="50" |
ItemStyle-VerticalAlign="Top" |
ItemStyle-Width="50" |
DataField="ID" /> |
<telerik:GridBoundColumn UniqueName="Name" |
HeaderText="Name" |
HeaderStyle-Width="150" |
ItemStyle-VerticalAlign="Top" |
ItemStyle-Width="150" |
DataField="Name" /> |
<telerik:GridBoundColumn UniqueName="DisplayOrder" |
HeaderText="Display Order" |
HeaderStyle-Width="100" |
ItemStyle-VerticalAlign="Top" |
ItemStyle-Width="100" |
DataField="DisplayOrder" /> |
<telerik:GridEditCommandColumn UniqueName="Edit" |
ButtonType="ImageButton" |
EditImageUrl="~/_Images/GIF/16x16/Edit.gif" |
ItemStyle-Width="50" /> |
<telerik:GridButtonColumn UniqueName="Delete" |
ButtonType="ImageButton" |
CommandName="Delete" |
Text="Delete" |
ConfirmText="Delete this pet type?" |
ConfirmTitle="Delete Pet Type" |
ImageUrl="~/_Images/GIF/16x16/Delete.gif" /> |
<telerik:GridTemplateColumn UniqueName="RightSpacer" |
HeaderStyle-Width="6" |
ItemStyle-Width="6"> |
<HeaderTemplate> |
|
</HeaderTemplate> |
</telerik:GridTemplateColumn> |
</Columns> |
</MasterTableView> |
</telerik:RadGrid> |
DataSource declaration:
<asp:SqlDataSource ID="SQLDataSource" |
ConnectionString="<%$ ConnectionStrings:MainConnectionString %>" |
ProviderName="System.Data.SqlClient" |
InsertCommand="INSERT INTO [dbo].[PetType] (ID, Name, DisplayOrder) VALUES (UPPER(@ID), @Name, @DisplayOrder)" |
SelectCommand="SELECT [ID], [Name], [DisplayOrder] FROM [dbo].[PetType] ORDER BY [DisplayOrder], [Name]" |
UpdateCommand="UPDATE [dbo].[PetType] SET [ID] = UPPER(@ID), [Name] = @Name, [DisplayOrder] = @DisplayOrder WHERE [ID] = @original_ID" |
DeleteCommand="DELETE FROM [dbo].[PetType] WHERE [ID] = @original_ID" |
OldValuesParameterFormatString="original_{0}" |
ConflictDetection="CompareAllValues" |
runat="server"> |
<InsertParameters> |
<asp:Parameter Name="ID" Type="String" /> |
<asp:Parameter Name="Name" Type="String" /> |
<asp:Parameter Name="DisplayOrder" Type="Int32" /> |
</InsertParameters> |
<UpdateParameters> |
<asp:Parameter Name="ID" Type="String" /> |
<asp:Parameter Name="Name" Type="String" /> |
<asp:Parameter Name="DisplayOrder" Type="Int32" /> |
<asp:Parameter Name="original_ID" Type="String" /> |
</UpdateParameters> |
<DeleteParameters> |
<asp:Parameter Name="original_ID" Type="String" /> |
</DeleteParameters> |
</asp:SqlDataSource> |