This is a migrated thread and some comments may be shown as answers.

[Solved] Sort TemplateColumn problem

1 Answer 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matías Ezequiel Sánchez
Top achievements
Rank 1
Matías Ezequiel Sánchez asked on 18 Jan 2010, 01:12 PM
Hello, i'm having a problem with the RadGrid, i have several columns, one of them has only numeric data, and the RadGrid sort it as text not as number. All columns are TemplateColumns, here is the code

        <telerik:RadGrid 
            ID="radGridShoppingCart" 
            runat="server" 
            Height="100%" 
            Width="100%" 
            GridLines="Both" 
            DataSourceID="oDsInfoDetalleCesta" 
            Skin="Default" 
            ShowStatusBar="true" 
            PageSize="5" 
            OnItemDataBound="radGridShoppingCart_ItemDataBound">             
            <MasterTableView 
                AutoGenerateColumns="false" 
                AllowAutomaticDeletes="false" 
                AllowAutomaticInserts="false" 
                AllowAutomaticUpdates="false" 
                AllowSorting="true" 
                AllowNaturalSort="true" 
                AllowPaging="true" 
                CellPadding="0" 
                CellSpacing="0" 
                PagerStyle-AlwaysVisible="true" 
                PagerStyle-Mode="NextPrevAndNumeric" 
                PagerStyle-Position="Bottom"
                <Columns> 
                    <telerik:GridTemplateColumn 
                        DataField="colItemNumber" 
                        DataType="System.Int32" 
                        Resizable="true" 
                        UniqueName="colItemNumber" 
                        HeaderStyle-HorizontalAlign="Center" 
                        ShowSortIcon="true" 
                        SortExpression="ITEM_NUMBER" 
                        HeaderStyle-Width="10%"
                        <ItemTemplate> 
                            <asp:Label 
                                ID="lblItemNumber" 
                                runat="server" 
                                CssClass="gridItem" 
                                Text='<% #Eval("ITEM_NUMBER") %>'
                            </asp:Label> 
                        </ItemTemplate> 
                        <ItemStyle 
                            HorizontalAlign="Center" /> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn 
                        DataField="colDescription" 
                        Resizable="true" 
                        UniqueName="colDescription" 
                        HeaderStyle-HorizontalAlign="Left" 
                        HeaderStyle-Width="45%" 
                        ShowSortIcon="true" 
                        SortExpression="DESCRIPTION"
                        <ItemTemplate> 
                            <asp:Label 
                                ID="lblDescription" 
                                runat="server" 
                                CssClass="gridItem" 
                                Text='<% #Eval("DESCRIPTION") %>'
                            </asp:Label> 
                        </ItemTemplate> 
                        <ItemStyle 
                            HorizontalAlign="Left" /> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn 
                        DataField="colQuantity" 
                        Resizable="true" 
                        UniqueName="colQuantity" 
                        HeaderStyle-HorizontalAlign="Right" 
                        HeaderStyle-Width="15%" 
                        ShowSortIcon="true" 
                        SortExpression="QUANTITY"
                        <ItemTemplate> 
                            <asp:Label 
                                ID="lblQuantity" 
                                runat="server" 
                                CssClass="gridItem" 
                                Text='<% #Eval("QUANTITY") %>'
                            </asp:Label> 
                        </ItemTemplate> 
                        <ItemStyle 
                            HorizontalAlign="Right" /> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn 
                        DataField="colUnit" 
                        Resizable="true" 
                        UniqueName="colUnit" 
                        HeaderStyle-HorizontalAlign="Center" 
                        HeaderStyle-Width="10%" 
                        ShowSortIcon="true" 
                        SortExpression="UNIT"
                        <ItemTemplate> 
                            <asp:Label 
                                ID="lblUnit" 
                                runat="server" 
                                CssClass="gridItem" 
                                Text='<% #Eval("UNIT") %>'
                            </asp:Label> 
                        </ItemTemplate> 
                        <ItemStyle 
                            HorizontalAlign="Center" /> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn 
                        DataField="colPrice" 
                        Resizable="true" 
                        UniqueName="colPrice" 
                        HeaderStyle-HorizontalAlign="Right" 
                        HeaderStyle-Width="20%" 
                        ShowSortIcon="true" 
                        SortExpression="PRICE"
                        <ItemTemplate> 
                            <asp:Label 
                                ID="lblPrice" 
                                runat="server" 
                                CssClass="gridItem" 
                                Text='<% #(((double.Parse(Eval("QUANTITY").ToString())) * (double.Parse(Eval("PRICE").ToString()))).ToString("N")) + " " + Eval("CURRENCY").ToString()%>'
                            </asp:Label> 
                        </ItemTemplate> 
                        <ItemStyle 
                            HorizontalAlign="Right" /> 
                    </telerik:GridTemplateColumn> 
                </Columns> 
                <HeaderStyle 
                    Font-Bold="true" 
                    Font-Names="Verdana" 
                    Font-Size="6.5pt" 
                    ForeColor="#000000" 
                    VerticalAlign="Middle" 
                    Wrap="true"/> 
                <ItemStyle 
                    Font-Names="Verdana" 
                    Font-Size="6.5pt" 
                    VerticalAlign="Middle" /> 
                <PagerStyle 
                    Font-Bold="true" 
                    Font-Names="Verdana" 
                    Font-Size="7.5pt" 
                    HorizontalAlign="Left" 
                    VerticalAlign="Middle" 
                    Mode="NumericPages" /> 
                <CommandItemStyle 
                    Font-Bold="true" 
                    Font-Names="Verdana" 
                    Font-Size="7.5pt "/> 
            </MasterTableView> 
        </telerik:RadGrid> 

The problem is with the colItemNumber column. Thanks in advance.

1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 18 Jan 2010, 03:26 PM
Hello Matías,

I suggest you review the following forum thread, which elaborates on this subject and let me know if it helps to achieve the desired functionality:
http://www.telerik.com/community/forums/aspnet/grid/numeric-value-sorting-in-gridtemplatecolumn.aspx

Kind regards,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Matías Ezequiel Sánchez
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or