总结ASPxGridView的使用 - 图文

2026/1/15 9:15:06

企部核对结果\PropertiesMemoEdit-Rows=\EditFormSettings-ColumnSpan=\/>

// 普通状态下的命令按钮显隐

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, \ 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 == \ {

ASPxComboBox combo = e.Editor as ASPxComboBox;

using (DbClean db = new DbClean()) {

combo.DataSource = db.ListUnits(); combo.TextField = \ combo.ValueField = \ combo.DataBind(); } }

// 新建状态除了id以外都可以编辑

if (gv.IsNewRowEditing) {

e.Editor.ReadOnly = (e.Column.FieldName == \ }

// 修改状态下根据角色可编辑部分数据

else {

e.Editor.ReadOnly = true;

if (e.Column.FieldName == \

e.Editor.ReadOnly = !Common.IsInRoles(WZWF.DAL.Roles.Admin);

else if (e.Column.FieldName == \|| e.Column.FieldName == \

e.Editor.ReadOnly = !Common.IsInRoles(WZWF.DAL.Roles.Admin, WZWF.DAL.Roles.MaintainDepartment);

else if (e.Column.FieldName == \

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[\ }

// 更新

protected void gv_RowUpdating(object sender, ASPxDataUpdatingEventArgs e) {

string unit = Convert.ToString(e.NewValues[\

string result = Convert.ToString(e.NewValues[\ string edCmt = Convert.ToString(e.NewValues[\ 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[\ } // 新增

protected void grid_InitNewRow(object sender, ASPxDataInitNewRowEventArgs e) {

e.NewValues[\= Page.User.Identity.Name; e.NewValues[\= System.DateTime.Now; }

protected void gv_RowInserting(object sender, ASPxDataInsertingEventArgs e) {

string unit = Convert.ToString(e.NewValues[\

string result = Convert.ToString(e.NewValues[\ string edCmt = Convert.ToString(e.NewValues[\ if (gv.IsNewRowEditing) {

using (DbClean db = new DbClean()) db.AddBasicNet(.....); }

e.Cancel = true; gv.CancelEdit();

ShowData(ViewState[\ }

(四)数据源

-- DataSource 支持的数据源 -- DataTable

-- IList

-- BindingList

-- XXXDataSource

--------------------------------------------------------- DataTable

grid.DataSource = dt; grid.DataBind(); IList

int articleId = Convert.ToInt32(Request.QueryString[\

IList images = BlogArticleImage.ListArticleImages(articleId);

this.gvImages.KeyFieldName = \ this.gvImages.DataSource = images; this.gvImages.DataBind();

BindingList

private void CreateQuotes() {

BindingList res = new BindingList(); foreach(string name in names) {

Quote q = new Quote(name);

q.Value = (decimal)GetRandom().Next(800, 2000) / (decimal)10; res.Add(q); }

Session[\= res; }

AccessDataSource

SelectCommand=\* FROM [Customers]\

DeleteCommand=\FROM [Customers] WHERE [CustomerID] = ?\

InsertCommand=\INTO [Customers] ([CustomerID], [CompanyName], [ContactName], [ContactTitle], [Address], [City], [Region], [PostalCode], [Country], [Phone], [Fax]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\ UpdateCommand=\[Customers] SET [CompanyName] = ?, [ContactName] = ?, [ContactTitle] = ?, [Address] = ?, [City] = ?, [Region] = ?, [PostalCode] = ?, [Country] = ?, [Phone] = ?, [Fax] = ? WHERE [CustomerID] = ?\ />


总结ASPxGridView的使用 - 图文.doc 将本文的Word文档下载到电脑
搜索更多关于: 总结ASPxGridView的使用 - 图文 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219