簡體   English   中英

在ASP.NET C#中對數據集進行排序

[英]Sorting dataset in asp.net c#

我正在嘗試對數據進行排序,但是當我從一頁跳到另一頁時,名稱卻沒有排序。

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。

公共數據集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;

更新

您可以簡單地執行以下操作:

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;
}

您可以嘗試以下方法。 記住,您不能為ds.Table []賦值。 因此,您需要創建一個新的數據表並將其添加到新的或現有的數據集中

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

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

您可以嘗試以下方法:

    //convert DataSet table to DataView  
    DataView dv = ds.Tables[0].DefaultView; 

    //apply the sort   
    dv.Sort = "grouptitle ASC"; 

    //save back into our dataset  
    ds.Tables[0] = dv.ToTable();  

DataView dv = ds.Tables [0] .DefaultView;

dv.Sort = "grouptitle ASC"; 

ds = dv.ToTable();  

試試這些

默認情況下,它位於ds.table [0]中,無需提及

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM