admin 管理员组文章数量: 1086019
2024年3月7日发(作者:ppt模板下载免费版简洁)
ASPxGridView属性:概述设置(Settings)
GridLines="Vertical" : 网格样式 Vertical, Both, None ShowGroupPanel="True" : 分组面板 ShowFooter="True" : 脚注面板 ShowFilterRow="True" : 过滤器行 ShowHeaderFilterButton="true" : 表头过滤按钮 ShowFilterBar :允许显示过滤工具条 ShowGroupFooter="VisibleAlways" : 分组脚注面板 Hidden | VisibleIfExpand | VisibleAlways ShowPreview="true" : 预览面板 ShowVerticalScrollBar="True" : 垂直滚动条 VerticalScrollableHeight="250" : 垂直滚动条 /> 行为设置(SettingsBehavior) AllowDragDrop="False" : 允许托拽 ColumnResizeMode="Control" : 列宽度调整模式 AllowFocusedRow="True" : 鼠标点击选择行 AllowSort :允许排序 AllowGroup :允许分组 autoExpandAllGroups :自动展开所有组 ConfirmDelete :允许提交删除 AllowMultiSelection :允许选择多行 /> 分页(SettingsPager) PageSize="30" : 分页大小 Mode="ShowAllRecords" : 展示模式 SEOFriendly="Enabled" : Search engine friendly Position="TopAndBottom" : 分页控件位置 > 文本设置(SettingsText) Title="标题" EmptyDataRow="无数据" PopupEditFormCaption="编辑" ConfirmDelete="确定删除?" /> Loading 面板设置(SettingsLoadingPanel) 编辑视图设置(SettingsEditing) PopupEditFormWidth = "600px" NewItemRowPosition = "Bottom" Mode = "PopupEditForm" /> 编辑模式 EditForm : 当前行转化为表单,嵌入在行中 EditFormAndDisplayRow : 同EditForm,但保留当前行 Inline : 在当前行现场编辑 PopupEditForm : 弹出窗口编辑 行详细设置(SettingDetail) AllowOnlyOneMasterRowExpanded :允许只展开一列详细信息 ShowDetailRow :允许显示详细列表 IsDetailGrid :允许显示分组 > 动态选中某一行: ection() 遍历所有行: 声明变量:DataRowView dv For(int i=0;i< RowCount;i++) { 选中行提取数据:if(elected(i)) { 行数据集 dv=(DataRowView)(i); } } ASPxGridView 样式 & 格式 --------------------------------------------------------- 集中式样式 列样式 数字日期格式 金额 时间 图像 ASPxGridView分组 & 汇总 & 排序 --------------------------------------------------------- 间隔分组:将时间日期字段按个性分组,如年、月、日、周、季度、上周、下周..... 汇总 分组汇总 ASPxGridView 列: --------------------------------------------------------- 基本列(GridViewDataColumn) 其他列 长文本列(GridViewDataMemoColumn) 编辑时展现为多行文本框 EditCellStyle-BackColor="Yellow" // 行的背景颜色 PropertiesMemoEdit-Rows="4" // 添加或是修改时 跨行 EditFormSettings-ColumnSpan="2" //添加或是修改时 跨列 /> 超链接列(GridViewDataHyperLinkColumn) 组合框列(GridViewDataComboBoxColumn) protected void grid_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e) { // 用下拉框展示国家下的所有城市 绑定数据源 if(ing && ame != "City" && !owEditing) { ASPxComboBox combo = as ASPxComboBox; string country = (string)ValuesByKeyValue(ue, "Country"); FillCityCombo(combo, country); } } 命令按钮列(GridViewCommandColumn) OnRowDeleting="gv_RowDeleting" OnRowUpdating="gv_RowUpdating" OnRowInserting="gv_RowInserting" 一种是添加图片的 一种就只这种标准的: 代码详见《nd》 复选框列 自定义按钮 “删除”按钮 protected void gv_CustomButtonCallback(object sender, ASPxGridViewCustomButtonCallbackEventArgs e) { if (ID == "DeleteFile") { long fileId = 64(Values(eIndex, "FileId")); string fileName = Values(eIndex, "FileName").ToString(); string filePath = alUploadFolder + Values(eIndex, "FilePath").ToString(); (filePath); using (DbFile db = new DbFile()) e(fileId); ShowData(tchId); } } “复制行”按钮 Hashtable copiedValues; protected void grid_CustomButtonCallback(object sender, ASPxGridViewCustomButtonCallbackEventArgs e) { if(ID == "Copy") { copiedValues = new Hashtable(); foreach(string fieldName in copiedFields) copiedValues[fieldName] = Values(eIndex, fieldName); Row(); } } protected void grid_InitNewRow(object sender, taInitNewRowEventArgs e) { if(copiedValues != null) foreach(string fieldName in copiedFields) ues[fieldName] = copiedValues[fieldName]; } 非绑定列(GridViewDataTextColumn) protected void grid_CustomUnboundColumnData(object sender, idViewColumnDataEventArgs e) { // Total = UnitPrice * Quantity if(ame == "Total") { decimal price = (decimal)tSourceFieldValue("UnitPrice"); int quantity = 32(tSourceFieldValue("Quantity")); = price * quantity; } } 模板列(GridViewDataTextColumn) onhtmlrowcreated="grid_HtmlRowCreated" &name=<%#Eval("FileName") %> " >下载 protected void grid_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e) { if (!ing && e == ) { // 操作 Label 控件 Label label = wCellTemplateControl(eIndex, null, "changePercent") as Label; decimal change = (decimal)Values(eIndex, "Change"); = ("{0:p}", change); // 操作 Image 控件 img = ()wCellTemplateControl(eIndex, null, "changeImage"); e = false; if(change != 0) { e = true; rl = change < 0 ? "~/Images/" : "~/Images/"; lor = change < 0 ? : ; } } } 注:模板列中的事件如何写?手工写事件,如k += ...; 注:视图模板请参考文档《tes》 ASPxGridView 事件 RowCreated(创建行数据时触发,类似 GridView 的 DataItemCreate 事件) protected void grid_HtmlRowCreated(object sender, idViewTableRowEventArgs e) { if(e != ) return; // 设置模板列lable控件值 Label label = wCellTemplateControl(eIndex, null, "changePercent") as Label; decimal change = (decimal)Values(eIndex, "Change"); = ("{0:p}", change); // 设置模板列image控件的图像 img = ()wCellTemplateControl(eIndex, null, "changeImage"); e = false; if(change != 0) { e = true; rl = change < 0 ? "~/Images/" : "~/Images/"; lor = change < 0 ? : ; } } HtmlRowPrepared(行准备?可在此设置行的展示效果,如背景) protected void grid_HtmlRowPrepared(object sender, ASPxGridViewTableRowEventArgs e) { bool hasError = ue("FirstName").ToString().Length <= 1; hasError = hasError || ue("LastName").ToString().Length <= 1; hasError = hasError || !ue("Email").ToString().Contains("@"); hasError = hasError || (int)ue("Age") < 18; DateTime arrival = (DateTime)ue("ArrivalDate"); hasError = hasError || != || != ; if(hasError) { lor = ; } } UnboundColumnData (非绑定列数据填充) protected void grid_CustomUnboundColumnData(object sender, idViewColumnDataEventArgs e) { if(ame == "Total") { decimal price = (decimal)tSourceFieldValue("UnitPrice"); int quantity = 32(tSourceFieldValue("Quantity")); = price * quantity; } } CustomColumnDisplayText(定制列文本展示) protected void grid_CustomColumnDisplayText(object sender, idViewColumnDisplayTextEventArgs e) { if((, s["Size"])) yText = GetSizeDisplayText(); } SummaryDisplayText(合计行文本展示) protected void grid_SummaryDisplayText(object sender, idViewSummaryDisplayTextEventArgs e) { if(ame == "Size") { = GetSizeDisplayText(); } } HeaderFilterFillItems(自定义过滤器处理逻辑) protected void grid_HeaderFilterFillItems(object sender, ASPxGridViewHeaderFilterEventArgs e) { if((, s["Total"])) { PrepareTotalFilterItems(e); return; } if((, s["Quantity"])) { PrepareQuantityFilterItems(e); return; } } --------------------------------------------------------- 回调处理 --------------------------------------------------------- CustomCallback(Ajax 回调处理) protected void grid_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) { int layoutIndex = -1; if(se(ters, out layoutIndex)) ApplyLayout(layoutIndex); // 更换布局 } CustomButtonCallback(定制按钮的ajax回调处理) protected void grid_CustomButtonCallback(object sender, ASPxGridViewCustomButtonCallbackEventArgs e) { if(ID != "Copy") return; copiedValues = new Hashtable(); foreach(string fieldName in copiedFields) copiedValues[fieldName] = Values(eIndex, fieldName); Row(); } --------------------------------------------------------- 编辑视图 --------------------------------------------------------- InitNewRow(新建行的数据初始化处理) protected void grid_InitNewRow(object sender, taInitNewRowEventArgs e) { if(copiedValues == null) return; foreach(string fieldName in copiedFields) { ues[fieldName] = copiedValues[fieldName]; } } CellEditorInitialize(编辑器初始化) protected void grid_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e) { if(ing && !owEditing && ame == "City") { string country = (string)ValuesByKeyValue(ue, "Country"); ASPxComboBox combo = as ASPxComboBox; FillCityCombo(combo, country); ck += new CallbackEventHandlerBase(cmbCity_OnCallback); } } StartRowEditing(开始编辑) protected void grid_StartRowEditing(object sender, artR owEditingEventArgs e) { if(!owEditing) { alidation(); } } RowValidating (行数据验证) protected void grid_RowValidating(object sender, taValidationEventArgs e) { foreach(GridViewColumn column in s) { GridViewDataColumn dataColumn = column as GridViewDataColumn; if(dataColumn == null) continue; if(ues[ame] == null) { [dataColumn] = "Value can't be null."; } } if( > 0) or = "Please, fill all fields."; if(ues["FirstName"] != null && ues["FirstName"].ToString().Length < 2) { AddError(, s["FirstName"], "First Name must be at least two characters long."); } if(ues["LastName"] != null && ues["LastName"].ToString().Length < 2) { AddError(, s["LastName"], "Last Name must be at least two characters long."); } if(ues["Email"] != null && !ues["Email"].ToString().Contains("@")) { AddError(, s["Email"], "Invalid e-mail."); } int age = 0; se(ues["Age"] == null ? : ues["Age"].ToString(), out age); if(age < 18) { AddError(, s["Age"], "Age must be greater than or equal 18."); } DateTime arrival = ue; se(ues["ArrivalDate"] == null ? : ues["ArrivalDate"].ToString(), out arrival); if( != || != ) { AddError(, s["ArrivalDate"], "Arrival date is required and must belong to the current month."); } if(OrEmpty(or) && > 0) or = "Please, correct all errors."; if (ues["Name"] == null) { or = "功能名称不能为空,请填写功能名称"; return; } if (ues["Remarks"] == null) { or = "功能备注不能为空,请填写功能备注"; return; } } 行修改事件 RowUpdating protected void gvFunction_RowUpdating(object sender, taUpdatingEventArgs e) { = ues[0].ToString();// 组名称 s = ues[1].ToString(); // 组备注 onId = [0].ToString();// ID rmodel = onEdit(functionModel);// 返回类型表 Edit();//结束编辑状态 = true; FunctionDataBind();//更新数据 } 行添加事件RowInserting protected void gvFunction_RowInserting(object sender, taInsertingEventArgs e) { = ues[0].ToString();// 组名称 s = ues[1].ToString(); // 组备注 rmodel = onSubmit(functionModel);// 返回类型表 Edit();//结束编辑状态 = true; FunctionDataBind();//更新数据 } 行删除事件RowDeleting protected void gvFunction_RowDeleting(object sender, taDeletingEventArgs e) { onId = [0].ToString();// ID onInfoDelete(functionModel); Edit();//结束编辑状态 = true; FunctionDataBind();//更新数据 } 初始化回调事件 Callback protected void callbackPanel_Callback(object sender, ckEventArgsBase e) { strGroupID = ng(); DataBindInfo();// 初始化页面信息 SelectUser();// 查找组里面的所有用户 DataCheck(); } 获取行展开改变事件 DetailRowExpandedChanged protected void gvGroup_DetailRowExpandedChanged(object sender, ASPxGridViewDetailRowEventArgs e) { SYSolution_nfo groupInfoModel = (SYSolution_nfo)((ASPxGridView)sender).GetRow(eIndex);// 获取选中行实体 ASPxGridView gv = (ASPxGridView)tailRowTemplateControl(eIndex, "gvGroupName"); // 获取模板内aspxgridView ID名称 SYSolution_nfo[] model = elUserList("GroupId='" + d + "'");// 通过组ID值获取实体对象 if (model[0].UserInfoList != null && gv != null)// 当用用户列表值与子aspxgridView不为空 { urce = model[0].UserInfoList; // 子aspxgridView绑定数据源 nd(); } if (model[0].UserInfoList[0].Name == "") // 如果子aspxgridView中的用户列表为空时不显示 不展开 { nlyOneMasterRowExpanded = false; } } 排序 事件中重新绑定数据 BeforeColumnSortingGrouping protected void gvGroup_BeforeColumnSortingGrouping(object sender, ASPxGridViewBeforeColumnGroupingSortingEventArgs e) { seAllRows();// 关闭所有DetailoRow Row(3); } 重绑定数据使用时先选中行,再查看 FocusedRowChanged Protected void aspxGridView_FocusedRowChanged(object sender,EventArgs e){} 行列绑定数据事件CustomUnboundColumnData Protected void aspxGridView_CustomUnboundColumnData(object sender,EventArgs e){} .隐藏编辑列,在DataBound事件中 protected void ASPxGridView1_DataBound(object sender, EventArgs e) { if(eRowCount>0) { //s[命令列索引] (s[4] as GridViewCommandColumn).e = false; } }
版权声明:本文标题:AspxGridView整理文档 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1709805407a546983.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论