开发者

Sort Substring of GridView in ASP.NET?

开发者 https://www.devze.com 2023-02-18 14:26 出处:网络
I have a column in my GridView which pulls in an individual\'s name. Unfortunately, the name is contained in one column in the database - both first and last. I\'d like to sort on the last name, not t

I have a column in my GridView which pulls in an individual's name. Unfortunately, the name is contained in one column in the database - both first and last. I'd like to sort on the last name, not the first...is there a way for me to tell the GridView to sort based on a substring? For example, names in this column might be:

  1. John Doe
  2. Jane Heck
  3. Mike Beck I'd like to somehow grab everything after the space in each column and sort on that, ignoring the开发者_JAVA技巧 first name, or even better - using the substring consisting of the first name to do sorts where the last name is identical.


If you can include the LastName into your data source, you could do something like this

<asp:boundfield datafield="FullName"
        headertext="Full Name"
        sortexpression="LastName"/>

If you are using SQL, then you can include

SUBSTRING(FullName, CHARINDEX(' ', FullName) + 1, LEN(FullName)) AS [LastName]

in you select.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号