在GridView中按月排序 [英] Sort by Month in GridView

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

问题描述





我的数据表中有一列DueMONTH。



ID姓名DueMonth

101 AAAAA 1月

102 cccc 5月

103 AAAAA 1月





我想在(Asp GridView或Devexpress GridView)中按月(1月,2月)对这个DueMonth进行排序。

月份列无法更改为数据库中的日期时间。



是否有其他可能来自Asp.net。



谢谢

Krishna

Hi,

I have datatable in which have a Column "DueMONTH".

ID Name DueMonth
101 AAAAA January
102 cccc May
103 AAAAA January


I want to sort this DueMonth in monthwise(January, Febuary) in (Asp GridView or Devexpress GridView).
The month column cannot be changed to Datetime in Database.

Is any other possible from Asp.net.

Thanks
Krishna

推荐答案

最简单的是添加一列到你的桌子。您不需要DB中的实际列,只需在select中添加一个列或在代码中添加到表中的新项,例如(VB):

Simplest is to add a column to your table. You don't need an actual column in the DB, just an extra column in your select or a new item added to your table in code, such as this (VB):
Dim dt As New DataTable
dt.Columns.Add("ID")
dt.Columns.Add("Name")
dt.Columns.Add("DueMonth")
dt.Columns.Add("SortMonth")
Const DayMonth As String = "01 2000"
dt.Rows.Add(New Object() {101, "AAAAA", "January", Date.Parse("January" & DayMonth).Month})
dt.Rows.Add(New Object() {102, "cccc", "May", Date.Parse("May" & DayMonth).Month})
dt.Rows.Add(New Object() {103, "AAAAA", "January", Date.Parse("January" & DayMonth).Month})
Dim dv As New DataView(dt)
dv.Sort = "SortMonth"
MessageBox.Show(dv(2)(2))





如何在SELECT语句中执行此操作取决于您的数据库类型。在Oracle中,它类似于



How you'd do it in your SELECT statement depends on your DB type. In Oracle, it'd be something like

select to_char(to_date('January','month'),'mm')



在SQLServer中,它更贴近代码:


In SQLServer, it's something closer to the code:

select DATEPART(MM, YourMonth + ' 01 2000')


这篇关于在GridView中按月排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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