代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Asp.Net
】
DevExpress ASPxGridView中进行编辑
作者:
Dezai.CN
/ 发布于
2013/4/23
/
1407
注意:想让GridView支持修改功能,必须指定KeyFieldName 展示编辑按钮列 <dxwgv:GridViewCommandColumn VisibleIndex="0"> <EditButton Visible="True" Text="修改" /> <DeleteButton Visible="true" Text="删除" /> <NewButton Visible="True" Text="新建" /> <CancelButton Visible="true" Text="取消" /> <UpdateButton Visible="true" Text="保存" /> <ClearFilterButton Visible="true" Text="取消过滤" /> </dxwgv:GridViewCommandColumn> 编辑视图下控件的外观设置»更多DevExpress开发资源与帮助文档 <dx:GridViewDataMemoColumn ... PropertiesMemoEdit-Rows="4" EditFormSettings-ColumnSpan="2" /> 或者 <dxwgv:GridViewDataMemoColumn FieldName="Notes" Visible="False"> <EditFormSettings RowSpan="4" ColumnSpan="2" /> </dxwgv:GridViewDataMemoColumn> 示例一: 绑定到IList并实现删除和修改 <dx:ASPxGridView runat="server" ID="gvImages" KeyFieldName="ImageId" OnRowDeleting= "gvImages_RowDeleting" OnRowUpdating="gvImages_RowUpdating" > <SettingsEditing Mode="Inline" /> <SettingsBehavior ConfirmDelete="true" /> <Columns> <dx:GridViewDataColumn FieldName="ImageId" Caption="ID" Visible="false" /> <dx:GridViewDataImageColumn FieldName="ThumbnailUrl" Caption="缩略图" PropertiesImage-DescriptionUrlField="ImageId" /> <dx:GridViewDataTextColumn FieldName="Description" Caption="说明" /> <dx:GridViewDataTextColumn FieldName="Keywords" Caption="关键字" /> <dx:GridViewCommandColumn Caption="编辑" > <EditButton Visible="True" Text="修改" /> <DeleteButton Visible="True" Text="删除" /> <CancelButton Text="取消" /> <UpdateButton Text="保存" /> </dx:GridViewCommandColumn> </Columns> </dx:ASPxGridView> // 展示 public void ShowArticleImages() { int articleId = Convert.ToInt32(Request.QueryString[ "articleId"]); IList <BlogArticleImage> images = BlogArticleImage.ListArticleImages(articleId); this.gvImages.KeyFieldName = "ImageId"; this.gvImages.DataSource = images; this.gvImages.DataBind(); } // 更新 protected void gvImages_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) { int id = Convert.ToInt32(e.Keys[0]); string descript = Convert.ToString(e.NewValues[ "Description"]); string keywords = Convert.ToString(e.NewValues[ "Keywords"]); BlogArticleImage image = BlogArticleImage.Retrieve(id); if (image != null) { image.Description = descript; image.Keywords = keywords; image.Persist(); } e.Cancel = true; gvImages.CancelEdit(); ShowArticleImages(); } // 删除 protected void gvImages_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e) { int id = Convert.ToInt32(e.Keys[0]); BlogArticleImage image = BlogArticleImage.Retrieve(id); if (image != null) { System.IO.File.Delete(Server.MapPath(image.ImageUrl)); System.IO.File.Delete(Server.MapPath(image.ThumbnailUrl)); image.Remove(); } e.Cancel = true; gvImages.CancelEdit(); ShowArticleImages(); } 示例二: 控件访问权限控制及CRUD操作 <dx:ASPxGridView runat="server" ID="gv" Caption="基础网" KeyFieldName="ID" Width="3000" OnRowDeleting= "gv_RowDeleting" OnRowUpdating="gv_RowUpdating" OnRowInserting="gv_RowInserting" OnInitNewRow= "grid_InitNewRow" onhtmlrowcreated="gv_HtmlRowCreated" OnCellEditorInitialize="grid_CellEditorInitialize" > <Columns> <dx:GridViewCommandColumn Caption="编辑" Width="60" > <EditButton Visible="True" Text="修改" /> <DeleteButton Visible="true" Text="删除" /> <NewButton Visible="True" Text="新建" /> <CancelButton Visible="true" Text="取消" /> <UpdateButton Visible="true" Text="保存" /> </dx:GridViewCommandColumn> <dx:GridViewDataColumn FieldName="ID" Caption="ID"/> <dx:GridViewDataColumn FieldName="CREATE_DT" Caption="创建时间"/> <dx:GridViewDataColumn FieldName="CREATOR" Caption="创建人"/> <dx:GridViewDataComboBoxColumn FieldName="UNIT" Caption="处理单位" > <PropertiesComboBox EnableSynchronization="False" EnableIncrementalFiltering="True" DropDownStyle="DropDown" /> </dx:GridViewDataComboBoxColumn> <dx:GridViewDataColumn FieldName="RESULT" Caption="处理结果" /> <dx:GridViewDataMemoColumn FieldName="ED_CMT" Caption="政企部核对结果" PropertiesMemoEdit-Rows="4" EditFormSettings-ColumnSpan="2" /> </Columns> </dx:ASPxGridView> // 普通状态下的命令按钮显隐 protected void gv_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e) { if (!gv.IsEditing && e.RowType == DevExpress.Web.ASPxGridView.GridViewRowType.Data) { bool isAdmin = Common.IsInRoles(new string[] { WZWF.DAL.Roles.Admin }); string unit = gv.GetRowValues(e.VisibleIndex, "UNIT").ToString(); bool isAuth = Common.IsInRoles( unit, WZWF.DAL.Roles.EnterpriseDepartment, WZWF.DAL.Roles.MaintainDepartment ); // 修改按钮 WebControl btnModify = e.Row.Cells[0].Controls[0] as WebControl; btnModify.Visible = isAuth; // 新建按钮 WebControl btnAddNew = e.Row.Cells[0].Controls[1] as WebControl; btnAddNew.Visible = isAdmin; // 删除按钮 WebControl btnDelete = e.Row.Cells[0].Controls[2] as WebControl; btnDelete.Visible = isAdmin; } } // 编辑状态下的控件访问权限控制 // 管理员:unit, result, md_cmt, ed_cmt // 政企部:ed_cmt // 网络维护部:result, md_cmt protected void grid_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e) { if (gv.IsEditing) { // 受理单位下拉框 if (e.Column.FieldName == "UNIT") { ASPxComboBox combo = e.Editor as ASPxComboBox; using (DbClean db = new DbClean()) { combo.DataSource = db.ListUnits(); combo.TextField = "ROLE"; combo.ValueField = "ROLE"; combo.DataBind(); } } // 新建状态除了id以外都可以编辑 if (gv.IsNewRowEditing) { e.Editor.ReadOnly = (e.Column.FieldName == "ID"); } // 修改状态下根据角色可编辑部分数据 else { e.Editor.ReadOnly = true; if (e.Column.FieldName == "UNIT") e.Editor.ReadOnly = !Common.IsInRoles(WZWF.DAL.Roles.Admin); else if (e.Column.FieldName == "RESULT" || e.Column.FieldName == "MD_CMT") e.Editor.ReadOnly = !Common.IsInRoles(WZWF.DAL.Roles.Admin, WZWF.DAL.Roles.MaintainDepartment); else if (e.Column.FieldName == "ED_CMT") e.Editor.ReadOnly = !Common.IsInRoles(WZWF.DAL.Roles.Admin, WZWF.DAL.Roles.EnterpriseDepartment); } } // 可编辑控件设置背景色 e.Editor.BackColor = e.Editor.ReadOnly ? Color.White : Color.LightYellow; } // 删除 protected void gv_RowDeleting(object sender, ASPxDataDeletingEventArgs e) { int id = Convert.ToInt32(e.Keys[0]); using (DbClean db = new DbClean()) db.DelBasicNet(id); e.Cancel = true; gv.CancelEdit(); ShowData(ViewState[ "Unit"].ToString()); } // 更新 protected void gv_RowUpdating(object sender, ASPxDataUpdatingEventArgs e) { string unit = Convert.ToString(e.NewValues[ "UNIT"]); string result = Convert.ToString(e.NewValues[ "RESULT"]); string edCmt = Convert.ToString(e.NewValues[ "ED_CMT"]); if (gv.IsEditing) { int id = Convert.ToInt32(e.Keys[0]); using (DbClean db = new DbClean()) db.ModBasicNet(id, ...); } e.Cancel = true; gv.CancelEdit(); ShowData(ViewState[ "Unit"].ToString()); } // 新增 protected void grid_InitNewRow(object sender, ASPxDataInitNewRowEventArgs e) { e.NewValues[ "CREATOR"] = Page.User.Identity.Name; e.NewValues[ "CREATE_DT"] = System.DateTime.Now; } protected void gv_RowInserting(object sender, ASPxDataInsertingEventArgs e) { string unit = Convert.ToString(e.NewValues[ "UNIT"]); string result = Convert.ToString(e.NewValues[ "RESULT"]); string edCmt = Convert.ToString(e.NewValues[ "ED_CMT"]); if (gv.IsNewRowEditing) { using (DbClean db = new DbClean()) db.AddBasicNet(.....); } e.Cancel = true; gv.CancelEdit(); ShowData(ViewState[ "Unit"].ToString()); }
试试其它关键字
ASPxGridView
同语言下
.
gzip压缩
.
实现http多线程断点续传下载文件
.
实现多线程断点续传下载大文件
.
生成字符串的 CheckSum
.
根据 UserAgent 获取浏览器的类型和版本
.
根据 Agent 判断是否是智能手机
.
隐藏手机号中间四位为*方法
.
合并图片(二维码和其他图片合并)
.
ASP.NET CORE中判断是否移动端打开网页
.
ASP.NET(C#)实现页面计时(定时)自动跳转
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3