惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
小众软件
小众软件
The Last Watchdog
The Last Watchdog
Latest news
Latest news
P
Palo Alto Networks Blog
C
Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
L
Lohrmann on Cybersecurity
P
Privacy International News Feed
NISL@THU
NISL@THU
T
Threat Research - Cisco Blogs
T
Threatpost
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
Spread Privacy
Spread Privacy
T
Tor Project blog
Cyberwarzone
Cyberwarzone
C
Cybersecurity and Infrastructure Security Agency CISA
AWS News Blog
AWS News Blog
S
Securelist
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy & Cybersecurity Law Blog
Hugging Face - Blog
Hugging Face - Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
CERT Recently Published Vulnerability Notes
V
Visual Studio Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
博客园 - 司徒正美
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
罗磊的独立博客
A
Arctic Wolf
腾讯CDC
WordPress大学
WordPress大学
IT之家
IT之家
Last Week in AI
Last Week in AI
博客园 - 聂微东
P
Proofpoint News Feed
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research
Hacker News: Ask HN
Hacker News: Ask HN
Help Net Security
Help Net Security
Blog — PlanetScale
Blog — PlanetScale
爱范儿
爱范儿
美团技术团队
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Tailwind CSS Blog

博客园 - Asharp

使用PowerShell批量修改项目文件的版本号 PowerShell因为在此系统中禁止执行脚本解决方法 .NET中zip的压缩和解压——SharpCompress .NET中zip的压缩和解压 【转】Face detection with getUserMedia 【转】Web实现音频、视频通信 【转】关于IPv6的六大误区:IPv6并非更安全 【转】Silverlight与Flex的比较选择 [转]12 很有用的 Chrome 浏览器命令 How to Set Up SSL on IIS 7 JavaScript实现md5加密 在64位系统32的.net应用程序出现CLR20R3错误 【转】CLR20R3 程序终止的几种解决方案 DevExpress的web.config配置 DevExpress的JavaScript脚本智能提示 加载托管C++程序集出现0x800736B1异常的解决方法 Exchange server 2007安装篇 使用Orca在Visual Studio安装项目中创建自定义对话框 Visual Assist X中文注释提示错误问题
【转】ASPxGridView 日期范围过滤扩展
Asharp · 2011-06-09 · via 博客园 - Asharp

使用方法:
Step 1:aspx页面中引用DateRange.js,代码清单如下:

   1: function ApplyFilter(dde, fieldname, dateFrom, dateTo, container) {
   2:     var d1 = dateFrom.GetText();
   3:     var d2 = dateTo.GetText();
   4:     if (d1 == "" || d2 == "")
   5:         return;
   6:     var newValue = d1 + " 至 " + d2;
   7:     var oldValue = dde.lastSuccessText;
   8:     dde.SetText(newValue);
   9:     if (newValue != oldValue)
  10:         container.AutoFilterByColumn(fieldname, dde.GetText());
  11: }
  12:  
  13: function RemoveFilter(dde, fieldname, container) {
  14:     dde.SetText('');
  15:     container.AutoFilterByColumn(fieldname, '');
  16: }
  17:  
  18: function OnDropDown(s, dateFrom, dateTo) {
  19:     var str = s.GetText();
  20:     if (str == "") {
  21:         dateFrom.SetDate(new Date(2011, 1, 1));
  22:         dateTo.SetDate(new Date());
  23:         return;
  24:     }
  25:     var d = str.split(" 至 ");
  26:     dateFrom.SetText(d[0]);
  27:     dateTo.SetText(d[1]);
  28: }

Step 2:App_Code中添加DateRange.cs,代码清单如下:

   1: using System;
   2: using System.Collections.Generic;
   3: using System.Web;
   4: using System.Web.UI;
   5: using System.Web.UI.WebControls;
   6: using DevExpress.Data.Filtering;
   7: using DevExpress.Web.ASPxEditors;
   8: using DevExpress.Web.ASPxGridView;
   9:  
  10: public class DateTemplate : ITemplate
  11: {
  12:     // client IDs of two ASPxDateEdit controls
  13:     public String cIdFrom;
  14:     public String cIdTo;
  15:     public String FieldName;
  16:     public ASPxGridView Container;
  17:  
  18:     public DateTemplate(ASPxGridView container, string fieldname)
  19:         : base()
  20:     {
  21:         Container = container;
  22:         FieldName = fieldname;
  23:     }
  24:  
  25:     public void InstantiateIn(Control container)
  26:     {
  27:         Table table = new Table();
  28:         container.Controls.Add(table);
  29:         TableRow row = new TableRow();
  30:         table.Rows.Add(row);
  31:  
  32:         TableCell cell = new TableCell();
  33:         row.Cells.Add(cell);
  34:         ASPxLabel lbl = new ASPxLabel();
  35:         lbl.ID = "lblFrom";
  36:         lbl.Text = "从:";
  37:         cell.Controls.Add(lbl);
  38:  
  39:         cell = new TableCell();
  40:         row.Cells.Add(cell);
  41:         ASPxDateEdit dateFrom = new ASPxDateEdit();
  42:         dateFrom.ID = "dateFrom";
  43:         dateFrom.EnableClientSideAPI = true;
  44:         cell.Controls.Add(dateFrom);
  45:  
  46:         row = new TableRow();
  47:  
  48:         table.Rows.Add(row);
  49:  
  50:         cell = new TableCell();
  51:         row.Cells.Add(cell);
  52:         lbl = new ASPxLabel();
  53:         lbl.ID = "lblTo";
  54:         lbl.Text = "到:";
  55:         cell.Controls.Add(lbl);
  56:  
  57:         cell = new TableCell();
  58:         row.Cells.Add(cell);
  59:         ASPxDateEdit dateTo = new ASPxDateEdit();
  60:         dateTo.ID = "dateTo";
  61:         dateTo.EnableClientSideAPI = true;
  62:         cell.Controls.Add(dateTo);
  63:  
  64:         cIdFrom = dateFrom.ClientID;
  65:         cIdTo = dateTo.ClientID;
  66:  
  67:         row = new TableRow();
  68:  
  69:         table.Rows.Add(row);
  70:  
  71:         cell = new TableCell();
  72:         cell.ColumnSpan = 2;
  73:         row.Cells.Add(cell);
  74:         ASPxHyperLink lnk = new ASPxHyperLink();
  75:         lnk.ID = "lnkApply";
  76:         lnk.Text = "应用";
  77:         lnk.NavigateUrl = "#";
  78:         lnk.ClientSideEvents.Click =
  79: String.Format("function (s, e) {{ {0}.HideDropDown(); ApplyFilter({0}, '{1}', {2}, {3}, {4}); }}",
  80:             container.NamingContainer.NamingContainer.ClientID, FieldName, cIdFrom, cIdTo, Container.ClientID);
  81:         cell.Controls.Add(lnk);
  82:  
  83:         Literal space = new Literal();
  84:         space.Text = "nbsp; ";
  85:         cell.Controls.Add(space);
  86:  
  87:         ASPxHyperLink lnkCancel = new ASPxHyperLink();
  88:         lnkCancel.ID = "lnkCancel";
  89:         lnkCancel.Text = "清除";
  90:         lnkCancel.NavigateUrl = "#";
  91:         lnkCancel.ClientSideEvents.Click =
  92: String.Format("function (s, e) {{ {0}.HideDropDown(); RemoveFilter({0}, '{1}', {2}); }}",
  93:             container.NamingContainer.NamingContainer.ClientID, FieldName, Container.ClientID);
  94:         cell.Controls.Add(lnkCancel);
  95:     }
  96: }
  97:  
  98:  
  99: public class DateRangeHandler
 100: {
 101:     DateTemplate dateTemplate = null;
 102:     List<string> FieldNames = null;
 103:  
 104:     public DateRangeHandler(ASPxGridView sender, string fieldname)
 105:     {
 106:         FieldNames = new List<string>();
 107:         FieldNames.Add(fieldname);
 108:         sender.AutoFilterCellEditorCreate += grid_AutoFilterCellEditorCreate;
 109:         sender.AutoFilterCellEditorInitialize += grid_AutoFilterCellEditorInitialize;
 110:         sender.ProcessColumnAutoFilter += grid_ProcessColumnAutoFilter;
 111:     }
 112:  
 113:     public DateRangeHandler(ASPxGridView sender, List<string> fieldnames)
 114:     {
 115:         FieldNames = fieldnames;
 116:         sender.AutoFilterCellEditorCreate += grid_AutoFilterCellEditorCreate;
 117:         sender.AutoFilterCellEditorInitialize += grid_AutoFilterCellEditorInitialize;
 118:         sender.ProcessColumnAutoFilter += grid_ProcessColumnAutoFilter;
 119:     }
 120:  
 121:     private void grid_AutoFilterCellEditorCreate(object sender, ASPxGridViewEditorCreateEventArgs e)
 122:     {
 123:         ASPxGridView grid = sender as ASPxGridView;
 124:         if (FieldNames.Contains(e.Column.FieldName))
 125:         {
 126:             DropDownEditProperties dde = new DropDownEditProperties();
 127:             dde.EnableClientSideAPI = true;
 128:  
 129:             dateTemplate = new DateTemplate(sender as ASPxGridView, e.Column.FieldName);
 130:  
 131:             dde.DropDownWindowTemplate = dateTemplate;
 132:             dde.Style.BorderLeft.BorderStyle = BorderStyle.Solid;
 133:             dde.Style.BorderRight.BorderStyle = BorderStyle.Solid;
 134:             dde.Style.BorderTop.BorderStyle = BorderStyle.Solid;
 135:             dde.Style.BorderBottom.BorderStyle = BorderStyle.Solid;
 136:             e.EditorProperties = dde;
 137:         }
 138:     }
 139:  
 140:     private void grid_AutoFilterCellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
 141:     {
 142:         ASPxGridView grid = sender as ASPxGridView;
 143:         if (FieldNames.Contains(e.Column.FieldName))
 144:         {
 145:             ASPxDropDownEdit dde = e.Editor as ASPxDropDownEdit;
 146:             //dde.ClientSideEvents.CloseUp = String.Format("function (s, e) {{ ApplyFilter(s,'{0}', {1}, {2}, {3}); }}",
 147:             //FieldName, dateTemplate.cIdFrom, dateTemplate.cIdTo, (sender as ASPxGridView).ClientID);
 148:             dde.ClientSideEvents.DropDown = String.Format("function (s, e) {{ OnDropDown(s, {0}, {1}, {2}); }}",
 149:                 dateTemplate.cIdFrom, dateTemplate.cIdTo, (sender as ASPxGridView).ClientID);
 150:             dde.ReadOnly = true;
 151:         }
 152:     }
 153:  
 154:     private void grid_ProcessColumnAutoFilter(object sender, ASPxGridViewAutoFilterEventArgs e)
 155:     {
 156:         if (e.Value == "")
 157:             return;
 158:         if (FieldNames.Contains(e.Column.FieldName))
 159:         {
 160:             if (e.Kind == GridViewAutoFilterEventKind.CreateCriteria)
 161:             {
 162:                 HttpContext.Current.Session["CollectionDateFilter_" + e.Column.FieldName] = e.Value;
 163:                 String[] dates = e.Value.Split(new string[] { " 至 " }, StringSplitOptions.RemoveEmptyEntries);
 164:                 DateTime dateFrom = Convert.ToDateTime(dates[0] + " 00:00:00"),
 165:                     dateTo = Convert.ToDateTime(dates[1] + " 23:59:59");
 166:                 e.Criteria = (new OperandProperty(e.Column.FieldName) >= dateFrom) 
 167:                              (new OperandProperty(e.Column.FieldName) <= dateTo);
 168:             }
 169:             else
 170:             {
 171:                 if (HttpContext.Current.Session["CollectionDateFilter_" + e.Column.FieldName] != null)
 172:                     e.Value = HttpContext.Current.Session["CollectionDateFilter_" + e.Column.FieldName].ToString();
 173:             }
 174:         }
 175:         else
 176:         {
 177:             if (e.Kind == GridViewAutoFilterEventKind.CreateCriteria)
 178:             {
 179:                 long dte = DateTime.Now.Ticks;
 180:                 e.Criteria = e.Criteria | (new OperandProperty(e.Column.FieldName) == dte);
 181:             }
 182:         }
 183:     }
 184: }

Step 3:页面.cs文件中添加如下代码:
单列方式:

   1:  
   2:     protected void Page_Load(object sender, EventArgs e)
   3:    {
   4:        DateRangeHandler h = new DateRangeHandler(grid, "创建时间");
   5:    }

多列方式:

   1:  
   2:     protected void Page_Load(object sender, EventArgs e)
   3:    {
   4:        List<string> fieldnames = new List<string>();
   5:        fieldnames.Add("创建时间");
   6:        fieldnames.Add("订货时间");
   7:        fieldnames.Add("出货时间");
   8:        fieldnames.Add("审核时间");
   9:        DateRangeHandler h = new DateRangeHandler(grid, fieldnames);
  10:    }

原文:http://smartsoft.5d6d.com/viewthread.php?tid=6727