在asp.net C#中排序数据 [英] Sorting dataset in asp.net c#

查看:249
本文介绍了在asp.net C#中排序数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对数据进行排序,但是当我从一个页面跳转到另一个名称不得到排序。

I'm trying to sort the data,however the names do not get sorted when I jump from one page to another.

return new dao_StudentGroupStudents().GetNewStudentbyGroup(bureauId, search, groupId, currentPage, pageSize, out totalCount);

    /// <summary>
    /// Get All the students from that Bureau.
    /// </summary>

    public DataSet GetAllStudentGroupByBureau(int? GroupId, int? BureauID)
    {
        DataSet ds = new dao_StudentGroup().GetDataSet(null, null, BureauID);
        ds.Tables[0].DefaultView.Sort = "grouptitle asc";
        return ds;
    }

我在输入这个,现在我得到找不到列COLUMNNAME。

I'm typing this in and now I get Cannot find column columnName.

公共数据集GetAllStudentGroupByBureau(INT?的GroupId,诠释?BureauID)
        {
    DataSet的DS =新dao_StudentGroup()GetDataSet(NULL,NULL,BureauID);

public DataSet GetAllStudentGroupByBureau(int? GroupId, int? BureauID) { DataSet ds = new dao_StudentGroup().GetDataSet(null, null, BureauID);

ds.Tables[0].DefaultView.Sort = "columnName ASC";

DataTable dt = ds.Tables[0].DefaultView.ToTable();

return ds;

}

推荐答案

试试这个:

DataSet ds = new dao_StudentGroup().GetDataSet(null, null, BureauID);
ds.Tables[0].DefaultView.Sort = "grouptitle asc";
ds.Tables[0] = ds.Tables[0].DefaultView.ToTable();
return ds;

更新

您可以简单地这样做,那么:

You can simply do this then:

public DataSet GetAllStudentGroupByBureau(int ? GroupId, int ? BureauID) 
{
    DataSet ds = new dao_StudentGroup().GetDataSet(null, null, BureauID);

    ds.Tables[0].DefaultView.Sort = "grouptitle asc";        
    DataTable dt = ds.Tables[0].DefaultView.ToTable();
    ds.Tables[0].Rows.Clear();
    foreach (DataRow row in dt.Rows)
       ds.Tables[0].Rows.Add(row.ItemArray);

    return ds;
}

这篇关于在asp.net C#中排序数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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