Sort table by Integer values - bind values as Integer

Sort table by Integer values - bind values as Integer

ValerelsValerels Posts: 2Questions: 1Answers: 0

Hi everyone,
I want to sort some column, but the values are String type. How can I bind values into the table by their real types, like integer; then sort the column. If the values are string I get sorting like 1,11,2,22,3.....
So I have 2 questions:
1. How to bind values by their real type (Int, DateTime...)
2. How to sort column, if the values are string and I need them to be Int.

Code HTML:


  • ValerelsValerels Posts: 2Questions: 1Answers: 0

    This is HTML code:

              <div runat="server" id="GridViewContainer" class ="grid" style="overflow-x:scroll;">
                    <asp:GridView ID="grvReport" runat="server" CssClass="display" BackColor="White" BorderColor="#DEDFDE" ClientIDMode="Static"
                        BorderStyle="None" BorderWidth="1px"  ForeColor="Black" GridLines="Vertical"
                        allowSorting="false" RowStyle-Wrap="false">
                       <%-- <AlternatingRowStyle BackColor="White" />--%>
                        <EditRowStyle HorizontalAlign="Right" />
                        <FooterStyle BackColor="#CCCC99" />
                        <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" CssClass="FrozenHeader" />
                        <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
                        <RowStyle BackColor="#F7F7DE" HorizontalAlign="Right" VerticalAlign="Middle" />
                        <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
                        <SortedAscendingCellStyle BackColor="#FBFBF2" HorizontalAlign="Right" />
                        <SortedAscendingHeaderStyle BackColor="#848384" />
                        <SortedDescendingCellStyle BackColor="#EAEAD3" />
                        <SortedDescendingHeaderStyle BackColor="#575357" />
  • colincolin Posts: 5,046Questions: 0Answers: 874

    Hi @Valerels ,

    It will sort numerically by default - see here.

    If that's not happening for you, it would suggest that there's a non-numeric value in that column. If that's not the case, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.



Sign In or Register to comment.