DataTable.DefaultView.Sort不排序 [英] DataTable.DefaultView.Sort Doesn't Sort

查看:92
本文介绍了DataTable.DefaultView.Sort不排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对DataTable.DefaultView.Sort感到困惑。以下是我要使用的代码段。

I am confused on DataTable.DefaultView.Sort. Here is the segment of the code I want to use it in.

actionLogDT.DefaultView.Sort = "StartDate";

foreach (CustomerService.ActionLogStartEndRow logRow in actionLogDT)
{
  // code here
}

我看到的示例不使用foreach循环,因此令我困惑的是如何处理这个。它不是按照我以为应该排序的。

The samples I have seen don't use the foreach loop and thus is confusing me on how to process this. It isn't sorting as I thought it should be.

我看到这个.DefaultView返回一个视图,而.Table提供了一个编译错误。

I see that .DefaultView returns a view, and .Table gives a compile error.

推荐答案

我不得不采取略有不同的方法。 这篇文章是我找到的最接近我的代码的工作。这是工作结果:

I had to take a slightly different approach. This post was the closest I could find to get my code to work. Here is the working result:

actionLogDT.DefaultView.Sort = "StartDate";
DataView dv = actionLogDT.DefaultView;

foreach (DataRowView logRow in dv) { . . . }

从那里我只需要将值重新转换成正确的类型。

From there I just have to cast the value back into it's proper type.

(string)logRow["Status"].ToString()

这篇关于DataTable.DefaultView.Sort不排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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