使用数据视图对数据集进行排序

发布于 2024-08-03 22:05:45 字数 422 浏览 10 评论 0原文

此代码正确获取数据并显示它;然而,这种排序完全被忽视了。

DataTable dt = f.Execute().Tables[0]; 
dt.DefaultView.Sort = summaryColumn;
rptInner.DataSource = dt.DefaultView;
rptInner.DataBind();

我可以做些什么来强制视图自行排序吗?

(f.Execute() 返回位置为 0 的 at table 的数据集,summaryColumn 是表中列的名称,rptInner 是重复器控件)

edit

summaryColumn 是一个字符串变量,具有精确的值我想要排序的列的名称。我没有使用存储过程或任何东西,数据集是给我的,我负责对其进行排序。

This code correctly fetches data, and displays it; however, the sort is completely ignroed.

DataTable dt = f.Execute().Tables[0]; 
dt.DefaultView.Sort = summaryColumn;
rptInner.DataSource = dt.DefaultView;
rptInner.DataBind();

Is there something I can do to force the view to sort itself?

(f.Execute() returns a dataset with at table at position 0, summaryColumn is the name of a column in the table, rptInner is a repeater control)

edit

summaryColumn is a string variable that has the exact name of the column I want to sort on. I am not using sproc or anything, the DataSet is given to me and I'm responsible for sorting it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨与橙与城 2024-08-10 22:05:45

如果summaryColumn是数据视图中要排序的列的名称,请将其放入双引号中:

DataTable dt = f.Execute().Tables[0]; 
DataView dv = dt.DefaultView;
dv.Sort = "summaryColumn";
rptInner.DataSource = dv;
rptInner.DataBind();

如果它是保存列名称的字符串变量,请确保它的值是所需列的确切字符串名称排序...

if summaryColumn is the name of the coulmn in the dataview that you want to sort on, put it into double quotes:

DataTable dt = f.Execute().Tables[0]; 
DataView dv = dt.DefaultView;
dv.Sort = "summaryColumn";
rptInner.DataSource = dv;
rptInner.DataBind();

If it's a string variable holding the name of the column, make sure it's value is the exact string name of the column you want to sort on...

嘦怹 2024-08-10 22:05:45

我在服务器端排序,如果您使用执行调用中的存储过程,请在结果集上放置一个 Order By 语句(如果是 SQL)。

I sort on the server side, if you are using a stored proc from the execute call put an Order By statement on the result set (if it is SQL).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文