Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9210159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:00:16+00:00 2026-06-18T01:00:16+00:00

Here’s the GridView: <asp:GridView ID=MyGridView runat=server AllowPaging=true AllowSorting=true OnPageIndexChanging=MyGridView_PageIndexChanging OnSorting=MyGridView_Sorting> <Columns> <asp:TemplateField HeaderText=ID SortExpression=Id>

  • 0

Here’s the GridView:

<asp:GridView ID="MyGridView" runat="server" AllowPaging="true" AllowSorting="true"
    OnPageIndexChanging="MyGridView_PageIndexChanging"
    OnSorting="MyGridView_Sorting">
    <Columns>
        <asp:TemplateField HeaderText="ID" SortExpression="Id">
            <ItemTemplate>
                <asp:Label ID="idLabel" runat="server" Text='<%# Bind("Id") %>' />
            </ItemTemplate>
       </asp:TemplateField>
    </Columns>
</asp:GridView>

Here, the Id column is a string consisting always of the letter “T” followed by a number, i.e. “T1” or “T597” The other columns are fairly ordinary name and description String fields.

I need this Id column to sort as though the Id were numeric, ignoring the letter in front. But because it is there, it is being treated as a String and sorting as such: T1, T10, T100, T2, T231, T34, …

So what I thought would be possible is:

protected void MyGridView_Sorting(object sender, GridViewSortEventArgs e)
{
    if (e.SortExpression.Equals("Id")
    {
         // Special sorting code
    }
    else
    {
        // Normal sorting code
    }
}

Where the “normal” sorting code follows the common pattern of converting the DataSource to DataView and setting DataView.Sort = e.SortExpression etc, for example: allow sorting by column gridview

So what do I do for the “special” sorting code?

UPDATE: Just to be clear, I have no trouble rolling my own function to compare two strings as I need. I do not, however, know how to apply that function to my Data Grid/ Data Source.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:00:17+00:00Added an answer on June 18, 2026 at 1:00 am

    The GridView allows DataKeyNames, and that is the solution here. When setting up the Data Source (in my case, a SQL query) include both the “FullId” and a “PlainId” which has stripped off the leading character and parsed the remainder as int. Use “FullId” as the column’s text value, but make “PlainId” one of the DataKeyNames and use that as the SortExpression for the column.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's how my DataTable looks like(2 columns: Name and Code ): Name Code name1
Here's the link: www.mchenry.edu/maps/google.asp Why won't the location balloon display correctly? Also, the pop-up
Here is my code for the POST request to the server. The JSON to
Here I am trying to retrieve the response from the server and display it,
Here is my context file.: <beans default-lazy-init=true xmlns=http://www.springframework.org/schema/beans xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:tx=http://www.springframework.org/schema/tx xsi:schemaLocation=http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
Here is the code in a function I'm trying to revise. This example works
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Here is my work environment: Eclipse Juno as IDE with maven2 plugin on it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.