如何根据子字符串对内容Telerik GridBoundColumn进行排序? [英] How can I sort the contents Telerik GridBoundColumn based upon a substring?

查看:86
本文介绍了如何根据子字符串对内容Telerik GridBoundColumn进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下内容:

<telerik:GridBoundColumn HeaderText="Name(s)" UniqueName="colNames" DataField="NameList"
                    AllowSorting="false">

与此绑定的数据来自SQL存储过程,在不影响许多其他页面的情况下,我无法对其进行修改.我需要按子字符串对这些项目进行排序;要显示的字段是姓氏名",我需要对姓氏进行排序.有没有一种方法可以修改以上内容以对''之后的子字符串进行排序?我知道这不是找到姓氏(F. Murray Abraham =='M')的不完美解决方案,但这是我要执行的方法.

the data being bound to this is coming from a SQL stored procedure that I can't modify without affecting a number of other pages. I need to sort these items by a substring; the field to be displayed is 'Firstname Lastname', and I need to sort on last name. Is there a way to modify the above to sort on the substring after ' '? I know this is an imperfect solution to finding the last name (F. Murray Abraham == 'M') but that's the approach that I'm tasked to implement.

我正在尝试使用Telerik SortExpression,但无法弄清楚语法(假设它甚至可以用于此目的).

I'm trying to use the Telerik SortExpression but can't get the syntax figured out (assuming that it's even usable for this purpose).

如果有帮助,则后面的站点代码是在VB.NET中构建的.

If it helps, the site codebehind is built in VB.NET.

推荐答案

最好的方法是通过将新列添加到包含姓氏的返回数据集中来修改存储的proc,前提是姓氏列与名.这不会影响已经在使用该存储过程的其他页面,除非您对这些页面的RadGrid使用AutoGeneratedColumn.

The best way is to modify the stored proc by adding new column to the returned dataset which contains the last name, provided the last name column is defined separately from the first name. This won't affect other pages which are already using the stored proc, unless you use AutoGeneratedColumn for the RadGrid on those pages.

如果从存储的proc返回的名称列是完整格式(即"John Smith")和/或无法从存储的proc向返回的数据集添加字段,则必须在代码隐藏:

If the name column returned from the stored proc is in full format (i.e "John Smith") and/or there is no way you can add field to the returned dataset from the stored proc, you will have to do this in code-behind:

  1. 执行存储的过程,并用返回的数据集填充DataTable
  2. 将新的类型为String的列"LastName"添加到DataTable对象
  3. 对于DataTable中的每一行,从"NameList"列中提取姓氏
  4. 将其分配给姓氏"列
  5. 将修改后的DataTable对象设置为RadGrid.DataSource

请记住将SortExpression ="LastName"添加到上方的GridBoundColumn标记中,并添加AllowSorting ="true".

Remember to add SortExpression="LastName" to your GridBoundColumn tag above and AllowSorting="true".

提取姓氏:

    If Not IsDBNull(row!NameList) Then
        Dim nameparts() As String = Cstr(row!NameList).Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries)
        If nameparts.Count > 0 Then
            row!lastname = nameparts.GetUpperBound(0)
        End If
    End If

这篇关于如何根据子字符串对内容Telerik GridBoundColumn进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆