gridview控件用法介绍 下载本文

组合框列(GridViewDataComboBoxColumn)

protected void grid_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e) {

// 用下拉框展示国家下的所有城市 绑定数据源

if(grid.IsEditing && e.Column.FieldName != \&& !grid.IsNewRowEditing) {

ASPxComboBox combo = e.Editor as ASPxComboBox;

string country = (string)grid.GetRowValuesByKeyValue(e.KeyValue, \ FillCityCombo(combo, country); } }

命令按钮列(GridViewCommandColumn)

OnRowDeleting=\OnRowUpdating=\OnRowInserting=\

一种是添加图片的

一种就只这种标准的:

代码详见《ASPxGridView.DataBind》 复选框列

自定义按钮 “删除”按钮

protected void gv_CustomButtonCallback(object sender, ASPxGridViewCustomButtonCallbackEventArgs e)

{

if (e.ButtonID == \ {

long fileId = Convert.ToInt64(gv.GetRowValues(e.VisibleIndex, \ string fileName = gv.GetRowValues(e.VisibleIndex, \ string filePath = Common.Config.Path.PhysicalUploadFolder + gv.GetRowValues(e.VisibleIndex, \ System.IO.File.Delete(filePath); using (DbFile db = new DbFile()) db.DelFile(fileId); ShowData(this.FileBatchId); } } “复制行”按钮

Hashtable copiedValues;

protected void grid_CustomButtonCallback(object sender, ASPxGridViewCustomButtonCallbackEventArgs e) {

if(e.ButtonID == \ {

copiedValues = new Hashtable(); foreach(string fieldName in copiedFields)

copiedValues[fieldName] = grid.GetRowValues(e.VisibleIndex, fieldName);

grid.AddNewRow(); } }

protected void grid_InitNewRow(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e) {

if(copiedValues != null)

foreach(string fieldName in copiedFields)

e.NewValues[fieldName] = copiedValues[fieldName]; }

非绑定列(GridViewDataTextColumn)

protected void grid_CustomUnboundColumnData(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDataEventArgs e) {

// Total = UnitPrice * Quantity if(e.Column.FieldName == \ {

decimal price = (decimal)e.GetListSourceFieldValue(\ int quantity = Convert.ToInt32(e.GetListSourceFieldValue(\ e.Value = price * quantity; } }

模板列(GridViewDataTextColumn)

onhtmlrowcreated=\

')\更多...

\>下载

protected void grid_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e) {