方法名 Assign
语法 Void
CollectionItem source)
中文说明
从指定对象中复制公共属
Assign(DevExpress.Web.ASPxClasses. 性到当前栏位。
AutoFilterBy GroupBy SortAscending UnGroup UnSort Void AutoFilterBy(string value) void GroupBy() void SortAscending() void UnGroup() Void UnSort() 根据指定栏位值自动过滤 按当前栏位分组。可以调用UnGroup方法打散分组。 按当前栏位值正序排序 按当前栏位值倒序排序 取消当前栏位分组 取消当前栏位排序 SortDescending Void SortDescending()
6.GridViewDataButtonEditColumn:编辑按钮列 (1) 栏位声明示例
15.AspxGridView列的个性设置
一、如何设置固定列
AspxGridView的固定列是通过设置栏位的FixedStyle=”Left”来实现的。 Asp.net中设置:FixedStyle=”Left”
C#中设置:FixedStyle = GridViewColumnFixedStyle.Left
二、如何设置可拖动列
设置SettingsBehavior.AllowDragDrop=true则允许栏位拖动。 调用客户端方法MoveColumn可在前台实现代码拖动。支持用户使用鼠标拖动栏位。
三、如何设置列合计值
AspxGridView的汇总数据是显示在Footer带上的,必须设置
Settings.ShowFooter=true。直接显示在栏位下方。 可以将汇总信息定义在
AspxGridView内置的聚合函数包括:Sum、Min、Max、Count、Average、Custom、None。
四、如何为列设置初始值
AspxGridView要设置栏位新增时初始值需要扩充其InitNewRow事件。代码的主要功能是给e.NewValues[列名称]赋值。 事件原型:
protected void ASPxGridView1_InitNewRow(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e)
DevExpress.Web.Data.ASPxDataInitNewRowEventArgs属性: NewValues:System.Collections.Specialized.OrderedDictionary类型
例:
//设置栏位初始值
rotected void ASPxGridView1_InitNewRow(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e) {
e.NewValues[\}
16.AspxGridView之数据校验
行数据校验(编辑状态)
调用DoRowValidation()可以进行行数据校验。它实际上是触发RowValidating事件编写代码实现数据校验的。DoRowValidation方法对浏览状态的行无效,可以通过获取AspxGridView的IsEditing属性判断是否进入编辑状态。
RowValidating事件原型:
void ASPxGridView1_RowValidating(object sender, DevExpress.Web.Data.ASPxDataValidationEventArgs e)
DevExpress.Web.Data.ASPxDataValidationEventArgs构造函数: public ASPxDataValidationEventArgs(bool isNew);
DevExpress.Web.Data.ASPxDataValidationEventArgs属性:
Errors: Dictionary
Keys:OrderedDictionary,要删除行的主键栏位值。只读。
NewValues: OrderedDictionary,要删除行的非主键(实际上是所有栏位)栏位新值。只读。
OldValues: OrderedDictionary,要删除行的非主键(实际上是所有栏位)栏位原值。只读。
RowError:string,行错误信息。可读写。
通常在RowValidating事件中检查栏位值是否有效,如果无效,应抛出异常。 例:
//行数据检验事件
protected void ASPxGridView1_RowValidating(object sender, DevExpress.Web.Data.ASPxDataValidationEventArgs e) {
//是否新增行 if (e.IsNewRow) {
if (e.NewValues[\ {
e.Errors.Add(this.ASPxGridView1.Columns[\事件名称不可为空\ e.RowError = \事件名称不可为空\ throw new Exception(\事件名称不可为空\ } } }
通常在HtmlRowPrepared事件中检查行是否有效并以不同的颜色来显示未通过校验的行。
通常在StartRowEditing事件中调用DoRowValidation方法触发数据校验。
以下是官方的示例代码:
using DevExpress.Web.ASPxGridView; using System.Collections.Generic;
protected void grid_RowValidating(object sender, DevExpress.Web.Data.ASPxDataValidationEventArgs e) {
// Checks for null values.
foreach (GridViewColumn column in grid.Columns) {
GridViewDataColumn dataColumn = column as GridViewDataColumn; if (dataColumn == null) continue;
if (e.NewValues[dataColumn.FieldName] == null) e.Errors[dataColumn] = \ }
// Displays the error row if there is at least one error. if (e.Errors.Count > 0) e.RowError = \
if (e.NewValues[\
e.NewValues[\ AddError(e.Errors, grid.Columns[\ \ }
if (e.NewValues[\
e.NewValues[\ AddError(e.Errors, grid.Columns[\ \ }
if (string.IsNullOrEmpty(e.RowError) && e.Errors.Count > 0) e.RowError = \}
void AddError(Dictionary
protected void grid_HtmlRowPrepared(object sender, ASPxGridViewTableRowEventArgs e) {
// Checks whether the generated row has the errors.
bool hasError = e.GetValue(\ hasError = hasError || e.GetValue(\ hasError = hasError || e.GetValue(\ // If the row has the error(s), its text color is set to red. if (hasError)
e.Row.ForeColor = System.Drawing.Color.Red; }
protected void grid_StartRowEditing(object sender,
DevExpress.Web.Data.ASPxStartRowEditingEventArgs e) { // Validates the edited row if it isn't a new row,. if (!grid.IsNewRowEditing) grid.DoRowValidation(); }
17.AspxGridView服务器事件列表
2.AutoFilterCellEditorCreate
(1)语法:publicdelegate void ASPxGridViewEditorCreateEventHandler(object sender, ASPxGridViewEditorCreateEventArgse);
ASPxGridViewEditorCreateEventArgs类包括以下属性: Column:GridViewDataColumn类型,只读。栏位实例。
EditorProperties:EditPropertiesBase类型,可读写。编辑器属性。 KeyValue:object类型。只读。关键栏位值。 Value:object类型。可读写。过滤栏位值。 VisibleIndex:int类型。只读。行号。
(2)英文说明:Enablesyou to assign editors to individual filter row cells.
(3)触发条件:必须显示了自动过滤工具条 要显示自动过滤行应该做如下设置:
this.ASPxGridView1.Settings.ShowFilterBar= DevExpress.Web.ASPxGridView.GridViewStatusBarMode.Visible;//显示自动过滤工具条
this.ASPxGridView1.Settings.ShowFilterRow= true;//显示自动过滤行
(4)中文说明:允许程序员为过滤行栏位指定个性化编辑器。
通常在该事件中初始化过滤行栏位的初始值、提供符合用户操作习惯的栏位编辑器(如采用下拉列表) 例:
switch (e.Column.FieldName) {
case\e.Value =DateTime.Now; break; default: break; }