ASPxGridView屬性:概述設置(Settings)
<Settings
GridLines="Vertical" : 網格樣式 Vertical, Both, None
ShowGroupPanel="True" : 分組面板
ShowFooter="True" : 腳註面板
ShowFilterRow="True" : 過濾器行
ShowHeaderFilterButton="true" : 表頭過濾按鈕javascript
ShowFilterBar :容許顯示過濾工具條
ShowGroupFooter="VisibleAlways" : 分組腳註面板 Hidden | VisibleIfExpand | VisibleAlways
ShowPreview="true" : 預覽面板
ShowVerticalScrollBar="True" : 垂直滾動條
VerticalScrollableHeight="250" : 垂直滾動條
/>html
行爲設置(SettingsBehavior)
<SettingsBehavior
AllowDragDrop="False" : 容許託拽
ColumnResizeMode="Control" : 列寬度調整模式
AllowFocusedRow="True" : 鼠標點擊選擇行java
AllowSort :容許排序ajax
AllowGroup :容許分組編輯器
autoExpandAllGroups :自動展開全部組工具
ConfirmDelete :容許提交刪除佈局
AllowMultiSelection :容許選擇多行ui
/>this
分頁(SettingsPager)
<SettingsPager
PageSize="30" : 分頁大小
Mode="ShowAllRecords" : 展現模式
SEOFriendly="Enabled" : Search engine friendly
Position="TopAndBottom" : 分頁控件位置
>
<Summary AllPagesText="頁: {0} / {1} ({2}行)" />
</SettingsPager>orm
文本設置(SettingsText)
<SettingsText
Title="標題"
EmptyDataRow="無數據"
PopupEditFormCaption="編輯"
ConfirmDelete="肯定刪除?"
/>
Loading 面板設置(SettingsLoadingPanel)
<SettingsLoadingPanel Mode="ShowOnStatusBar" />
編輯視圖設置(SettingsEditing)
<SettingsEditing
PopupEditFormWidth = "600px"
NewItemRowPosition = "Bottom"
Mode = "PopupEditForm"
/>
編輯模式 SettingsEditing.Mode
EditForm : 當前行轉化爲表單,嵌入在行中
EditFormAndDisplayRow : 同EditForm,但保留當前行
Inline : 在當前行現場編輯
PopupEditForm : 彈出窗口編輯
行詳細設置(SettingDetail)
<SettingDetail
AllowOnlyOneMasterRowExpanded :容許只展開一列詳細信息
ShowDetailRow :容許顯示詳細列表
IsDetailGrid :容許顯示分組
>
動態選中某一行:
AspxgridView1.Selection.SetSelection(i.true)
遍歷全部行:
聲明變量:DataRowView dv
For(int i=0;i< AspxgridView1.VisbleRowCount;i++)
{
選中行提取數據:if(AspxgridView1.Selection.IsRowSelected(i))
{
行數據集 dv=(DataRowView)AspxgridView1.GetRow(i);
}
}
ASPxGridView樣式 & 格式
---------------------------------------------------------
集中式樣式
<Styles>
<Header HorizontalAlign="Center" /> : 標題居中對齊
<AlternatingRow Enabled="true"/> : 交錯行效果
<CommandColumn Paddings-Padding="1" /> :
</Styles>
列樣式
<dxwgv:GridViewDataTextColumn FieldName="Total" UnboundType="Decimal">
<FooterCellStyle ForeColor="Brown"/>
</dxwgv:GridViewDataTextColumn>
數字日期格式
金額
<dxwgv:GridViewDataTextColumn FieldName="UnitPrice" >
<PropertiesTextEdit DisplayFormatString="c" />
</dxwgv:GridViewDataTextColumn>
時間
<dxwgv:GridViewDataDateColumn Caption="Time" FieldName="Time">
<PropertiesDateEdit DisplayFormatString="HH:mm:ss" />
<CellStyle HorizontalAlign="Right" />
</dxwgv:GridViewDataDateColumn>
圖像
<Images ImageFolder="~/App_Themes/Glass/{0}/">
<CollapsedButton Height="12px" Width="11px" />
<DetailCollapsedButton Height="9px" Width="9px" />
<PopupEditFormWindowClose Height="17px" Width="17px" />
</Images>
ASPxGridView分組 & 彙總 & 排序
---------------------------------------------------------
間隔分組:將時間日期字段按個性分組,如年、月、日、周、季度、上週、下週.....
<dxwgv:GridViewDataDateColumn FieldName="OrderDate" VisibleIndex="3" GroupIndex="0">
<Settings GroupInterval="DateYear"/>
</dxwgv:GridViewDataDateColumn>
彙總
<TotalSummary>
<dxwgv:ASPxSummaryItem FieldName="CompanyName" SummaryType="Count"/>
<dxwgv:ASPxSummaryItem FieldName="Total" SummaryType="Sum" DisplayFormat="c"/>
<dxwgv:ASPxSummaryItem FieldName="Quantity" SummaryType="Min" />
<dxwgv:ASPxSummaryItem FieldName="Quantity" SummaryType="Average" />
<dxwgv:ASPxSummaryItem FieldName="Quantity" SummaryType="Max" />
</TotalSummary>
分組彙總
<GroupSummary>
<dxwgv:ASPxSummaryItem FieldName="Country" SummaryType="Count" />
<dxwgv:ASPxSummaryItem FieldName="Quantity" SummaryType="Sum" />
<dxwgv:ASPxSummaryItem FieldName="Total" SummaryType="Sum" DisplayFormat="{0:c}"/>
</GroupSummary>
ASPxGridView 列:
---------------------------------------------------------
基本列(GridViewDataColumn)
<dxwgv:GridViewDataColumn FieldName="Country" VisibleIndex="5" />
其餘列
<dx:GridViewDataTextColumn /> : 文本列
<dx:GridViewDataMemoColumn /> : 長文本列
<dx:GridViewDataImageColumn /> : 圖像列
<dx:GridViewDataBinaryImageColumn /> : 二進制圖像列
<dx:GridViewDataDateColumn /> : 日期列
<dx:GridViewDataTimeEditColumn /> : 時間列
<dx:GridViewDataComboBoxColumn /> : 組合框列
<dx:GridViewDataDropDownEditColumn /> : 下拉框編輯列?
<dx:GridViewCommandColumn /> : 命令按鈕列
<dx:GridViewDataButtonEditColumn /> : 編輯按鈕列?
<dx:GridViewDataCheckColumn /> : 複選框列
<dx:GridViewDataColorEditColumn /> : 色彩列
<dx:GridViewDataHyperLinkColumn /> : 超連接列
<dx:GridViewDataProgressBarColumn /> : 進度條列
<dx:GridViewDataSpinEditColumn /> : SpinEdit列
長文本列(GridViewDataMemoColumn)
編輯時展示爲多行文本框
<dx:GridViewDataMemoColumn FieldName="Remarks" Caption="備註"
EditCellStyle-BackColor="Yellow" // 行的背景顏色
PropertiesMemoEdit-Rows="4" // 添加或是修改時跨行
EditFormSettings-ColumnSpan="2" //添加或是修改時跨列
/>
超連接列(GridViewDataHyperLinkColumn)
<dx:GridViewDataHyperLinkColumn FieldName="ArticleId" Caption="查看" >
<PropertiesHyperLinkEdit Text="查看" TextFormatString="" />
</dx:GridViewDataHyperLinkColumn>
組合框列(GridViewDataComboBoxColumn)
<dx:ASPxGridView OnCellEditorInitialize="grid_CellEditorInitialize">
<dxwgv:GridViewDataComboBoxColumn FieldName="City" VisibleIndex="2">
<PropertiesComboBox EnableSynchronization="False" EnableIncrementalFiltering="True" DropDownStyle="DropDown" />
</dxwgv:GridViewDataComboBoxColumn>
</dx:ASPxGridView>
protected void grid_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
{
// 用下拉框展現國家下的全部城市綁定數據源
if(grid.IsEditing && e.Column.FieldName != "City" && !grid.IsNewRowEditing)
{
ASPxComboBox combo = e.Editor as ASPxComboBox;
string country = (string)grid.GetRowValuesByKeyValue(e.KeyValue, "Country");
FillCityCombo(combo, country);
}
}
命令按鈕列(GridViewCommandColumn)
<dx:ASPxGridView runat="server" KeyFieldName="ID"
OnRowDeleting="gv_RowDeleting" OnRowUpdating="gv_RowUpdating" OnRowInserting="gv_RowInserting"
<Columns>
一種是添加圖片的 <dx:GridViewCommandColumn VisibleIndex="0" ButtonType="Image" Caption=操做">
<EditButton Visible="True">
<Image ToolTip="修改" Url="Images/edit.png" />
</EditButton>
<NewButton Visible="True">
<Image ToolTip="新建" Url="Images/new.png" />
</NewButton>
<DeleteButton Visible="true">
<Image ToolTip="刪除" Url="Images/del.png" />
</DeleteButton>
<CancelButton Visible="True">
<Image ToolTip="關閉" Url="Images/cancel.png" />
</CancelButton>
<UpdateButton Visible="True">
<Image ToolTip="保存" Url="Images/update.png" />
</UpdateButton>
<ClearFilterButton Visible="true">
<Image ToolTip="清空" Url="Images/del2.png" />
</ClearFilterButton>
<HeaderStyle HorizontalAlign="Center" />
</dx:GridViewCommandColumn>
一種就只這種標準的: <dxwgv:GridViewCommandColumn>
<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>
</Columns>
</dx:ASPxGridView>
代碼詳見《ASPxGridView.DataBind》
複選框列
<dxwgv:GridViewCommandColumn ShowSelectCheckbox="True"/>
<dxwgv:GridViewCommandColumn ShowSelectCheckbox="True">
<HeaderTemplate>
<input type="checkbox" onclick="grid.SelectAllRowsOnPage(this.checked);" title="選擇/放棄選擇本頁的全部行" />
</HeaderTemplate>
<HeaderStyle HorizontalAlign="Center" />
</dxwgv:GridViewCommandColumn>
自定義按鈕
「刪除」按鈕
<dx:GridViewCommandColumn Caption="刪除">
<CustomButtons>
<dx:GridViewCommandColumnCustomButton ID="DeleteFile" Text="刪除" />
</CustomButtons>
</dx:GridViewCommandColumn>
protected void gv_CustomButtonCallback(object sender, ASPxGridViewCustomButtonCallbackEventArgs e)
{
if (e.ButtonID == "DeleteFile")
{
long fileId = Convert.ToInt64(gv.GetRowValues(e.VisibleIndex, "FileId"));
string fileName = gv.GetRowValues(e.VisibleIndex, "FileName").ToString();
string filePath = Common.Config.Path.PhysicalUploadFolder + gv.GetRowValues(e.VisibleIndex, "FilePath").ToString();
System.IO.File.Delete(filePath);
using (DbFile db = new DbFile())
db.DelFile(fileId);
ShowData(this.FileBatchId);
}
}
「複製行」按鈕
<dx:ASPxGridView runat="server" OnCustomButtonCallback="grid_CustomButtonCallback">
<Columns>
<dxwgv:GridViewCommandColumn VisibleIndex="0">
<CustomButtons>
<dxwgv:GridViewCommandColumnCustomButton Text="複製行" ID="Copy" />
</CustomButtons>
</dxwgv:GridViewCommandColumn>
</Columns>
</dx:ASPxGridView>
Hashtable copiedValues;
protected void grid_CustomButtonCallback(object sender, ASPxGridViewCustomButtonCallbackEventArgs e)
{
if(e.ButtonID == "Copy")
{
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)
<dxwgv:GridViewDataTextColumn FieldName="Total" UnboundType="Decimal" />
protected void grid_CustomUnboundColumnData(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDataEventArgs e)
{
// Total = UnitPrice * Quantity
if(e.Column.FieldName == "Total")
{
decimal price = (decimal)e.GetListSourceFieldValue("UnitPrice");
int quantity = Convert.ToInt32(e.GetListSourceFieldValue("Quantity"));
e.Value = price * quantity;
}
}
模板列(GridViewDataTextColumn)
onhtmlrowcreated="grid_HtmlRowCreated"
<dxwgv:GridViewDataTextColumn Name="Percent" Caption="Change" FieldName="Change">
<DataItemTemplate>
<asp:Image ID="changeImage" runat="server" ImageUrl="~/Images/arGreen.gif" Visible="false" GenerateEmptyAlternateText="True" />
<asp:Label ID="changePercent" runat="server" Text="" />
<a href="javascript:void(0);" onclick="OnMoreInfoClick(this, '<%# Container.KeyValue %>')">更多...</a>
<a href="../pages/download.ashx?path=../uploads/<%#Eval("FilePath")%>&name=<%#Eval("FileName") %> " >下載</a>
</DataItemTemplate>
</dxwgv:GridViewDataTextColumn>
protected void grid_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e)
{
if (!grid.IsEditing && e.RowType == DevExpress.Web.ASPxGridView.GridViewRowType.Data)
{
// 操做 Label 控件
Label label = grid.FindRowCellTemplateControl(e.VisibleIndex, null, "changePercent") as Label;
decimal change = (decimal)grid.GetRowValues(e.VisibleIndex, "Change");
label.Text = string.Format("{0:p}", change);
// 操做 Image 控件
System.Web.UI.WebControls.Image img = (System.Web.UI.WebControls.Image)grid.FindRowCellTemplateControl(e.VisibleIndex, null, "changeImage");
img.Visible = false;
if(change != 0)
{
img.Visible = true;
img.ImageUrl = change < 0 ? "~/Images/arRed.gif" : "~/Images/arGreen.gif";
label.ForeColor = change < 0 ? Color.Red : Color.Green;
}
}
}
注:模板列中的事件如何寫?手工寫事件,如btn.OnClick += ...;
注:視圖模板請參考文檔《ASPxGridView.Templates》
ASPxGridView 事件
RowCreated(建立行數據時觸發,相似 GridView 的 DataItemCreate 事件)
protected void grid_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
{
if(e.RowType != DevExpress.Web.ASPxGridView.GridViewRowType.Data) return;
// 設置模板列lable控件值
Label label = grid.FindRowCellTemplateControl(e.VisibleIndex, null, "changePercent") as Label;
decimal change = (decimal)grid.GetRowValues(e.VisibleIndex, "Change");
label.Text = string.Format("{0:p}", change);
// 設置模板列image控件的圖像
System.Web.UI.WebControls.Image img = (System.Web.UI.WebControls.Image)grid.FindRowCellTemplateControl(e.VisibleIndex, null, "changeImage");
img.Visible = false;
if(change != 0) {
img.Visible = true;
img.ImageUrl = change < 0 ? "~/Images/arRed.gif" : "~/Images/arGreen.gif";
label.ForeColor = change < 0 ? Color.Red : Color.Green;
}
}
HtmlRowPrepared(行準備?可在此設置行的展現效果,如背景)
protected void grid_HtmlRowPrepared(object sender, ASPxGridViewTableRowEventArgs e)
{
bool hasError = e.GetValue("FirstName").ToString().Length <= 1;
hasError = hasError || e.GetValue("LastName").ToString().Length <= 1;
hasError = hasError || !e.GetValue("Email").ToString().Contains("@");
hasError = hasError || (int)e.GetValue("Age") < 18;
DateTime arrival = (DateTime)e.GetValue("ArrivalDate");
hasError = hasError || DateTime.Today.Year != arrival.Year || DateTime.Today.Month != arrival.Month;
if(hasError) {
e.Row.ForeColor = System.Drawing.Color.Red;
}
}
UnboundColumnData (非綁定列數據填充)
protected void grid_CustomUnboundColumnData(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDataEventArgs e)
{
if(e.Column.FieldName == "Total")
{
decimal price = (decimal)e.GetListSourceFieldValue("UnitPrice");
int quantity = Convert.ToInt32(e.GetListSourceFieldValue("Quantity"));
e.Value = price * quantity;
}
}
CustomColumnDisplayText(定製列文本展現)
protected void grid_CustomColumnDisplayText(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDisplayTextEventArgs e)
{
if(object.Equals(e.Column, grid.Columns["Size"]))
e.DisplayText = GetSizeDisplayText(e.Value);
}
SummaryDisplayText(合計行文本展現)
protected void grid_SummaryDisplayText(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewSummaryDisplayTextEventArgs e) {
if(e.Item.FieldName == "Size") {
e.Text = GetSizeDisplayText(e.Value);
}
}
HeaderFilterFillItems(自定義過濾器處理邏輯)
protected void grid_HeaderFilterFillItems(object sender, ASPxGridViewHeaderFilterEventArgs e)
{
if(object.Equals(e.Column, grid.Columns["Total"])) {
PrepareTotalFilterItems(e);
return;
}
if(object.Equals(e.Column, grid.Columns["Quantity"])) {
PrepareQuantityFilterItems(e);
return;
}
}
---------------------------------------------------------
回調處理
---------------------------------------------------------
CustomCallback(Ajax 回調處理)
<select id="selGridLayout" onchange="grid.PerformCallback(this.value);" >
<option selected="selected" value="0">Country</option>
<option value="1">Country, City</option>
<option value="2">Company Name</option>
</select>
protected void grid_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
{
int layoutIndex = -1;
if(int.TryParse(e.Parameters, out layoutIndex))
ApplyLayout(layoutIndex); // 更換佈局
}
CustomButtonCallback(定製按鈕的ajax回調處理)
protected void grid_CustomButtonCallback(object sender, ASPxGridViewCustomButtonCallbackEventArgs e)
{
if(e.ButtonID != "Copy") return;
copiedValues = new Hashtable();
foreach(string fieldName in copiedFields)
copiedValues[fieldName] = grid.GetRowValues(e.VisibleIndex, fieldName);
grid.AddNewRow();
}
---------------------------------------------------------
編輯視圖
---------------------------------------------------------
InitNewRow(新建行的數據初始化處理)
protected void grid_InitNewRow(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e)
{
if(copiedValues == null) return;
foreach(string fieldName in copiedFields) {
e.NewValues[fieldName] = copiedValues[fieldName];
}
}
CellEditorInitialize(編輯器初始化)
protected void grid_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
{
if(grid.IsEditing && !grid.IsNewRowEditing && e.Column.FieldName == "City")
{
string country = (string)grid.GetRowValuesByKeyValue(e.KeyValue, "Country");
ASPxComboBox combo = e.Editor as ASPxComboBox;
FillCityCombo(combo, country);
combo.Callback += new CallbackEventHandlerBase(cmbCity_OnCallback);
}
}
StartRowEditing(開始編輯)
protected void grid_StartRowEditing(object sender, DevExpress.Web.Data.ASPxStartRowEditingEventArgs e)
{
if(!grid.IsNewRowEditing) {
grid.DoRowValidation();
}
}
RowValidating (行數據驗證)
protected void grid_RowValidating(object sender, DevExpress.Web.Data.ASPxDataValidationEventArgs e)
{
foreach(GridViewColumn column in grid.Columns) {
GridViewDataColumn dataColumn = column as GridViewDataColumn;
if(dataColumn == null) continue;
if(e.NewValues[dataColumn.FieldName] == null) {
e.Errors[dataColumn] = "Value can't be null.";
}
}
if(e.Errors.Count > 0) e.RowError = "Please, fill all fields.";
if(e.NewValues["FirstName"] != null && e.NewValues["FirstName"].ToString().Length < 2) {
AddError(e.Errors, grid.Columns["FirstName"], "First Name must be at least two characters long.");
}
if(e.NewValues["LastName"] != null && e.NewValues["LastName"].ToString().Length < 2) {
AddError(e.Errors, grid.Columns["LastName"], "Last Name must be at least two characters long.");
}
if(e.NewValues["Email"] != null && !e.NewValues["Email"].ToString().Contains("@")) {
AddError(e.Errors, grid.Columns["Email"], "Invalid e-mail.");
}
int age = 0;
int.TryParse(e.NewValues["Age"] == null ? string.Empty : e.NewValues["Age"].ToString(), out age);
if(age < 18) {
AddError(e.Errors, grid.Columns["Age"], "Age must be greater than or equal 18.");
}
DateTime arrival = DateTime.MinValue;
DateTime.TryParse(e.NewValues["ArrivalDate"] == null ? string.Empty : e.NewValues["ArrivalDate"].ToString(), out arrival);
if(DateTime.Today.Year != arrival.Year || DateTime.Today.Month != arrival.Month) {
AddError(e.Errors, grid.Columns["ArrivalDate"], "Arrival date is required and must belong to the current month.");
}
if(string.IsNullOrEmpty(e.RowError) && e.Errors.Count > 0) e.RowError = "Please, correct all errors.";
if (e.NewValues["Name"] == null)
{
e.RowError = "功能名稱不能爲空,請填寫功能名稱";
return;
}
if (e.NewValues["Remarks"] == null)
{
e.RowError = "功能備註不能爲空,請填寫功能備註";
return;
}
}
行修改事件 RowUpdating
protected void gvFunction_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
{
functionModel.Name = e.NewValues[0].ToString();// 組名稱
functionModel.Remarks = e.NewValues[1].ToString(); // 組備註
functionModel.FunctionId = e.Keys[0].ToString();// ID
rmodel = client.FunctionEdit(functionModel);// 返回類型表
gvFunction.CancelEdit();//結束編輯狀態
e.Cancel = true;
FunctionDataBind();//更新數據
}
行添加事件RowInserting
protected void gvFunction_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
{
functionModel.Name = e.NewValues[0].ToString();// 組名稱
functionModel.Remarks = e.NewValues[1].ToString(); // 組備註
rmodel = client.FunctionSubmit(functionModel);// 返回類型表
gvFunction.CancelEdit();//結束編輯狀態
e.Cancel = true;
FunctionDataBind();//更新數據
}
行刪除事件RowDeleting
protected void gvFunction_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
{
functionModel.FunctionId = e.Keys[0].ToString();// ID
client.FunctionInfoDelete(functionModel);
gvFunction.CancelEdit();//結束編輯狀態
e.Cancel = true;
FunctionDataBind();//更新數據
}
初始化回調事件 Callback
protected void callbackPanel_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
{
strGroupID = e.Parameter.ToString();
DataBindInfo();// 初始化頁面信息
SelectUser();// 查找組裏面的全部用戶
DataCheck();
}
獲取行展開改變事件 DetailRowExpandedChanged
protected void gvGroup_DetailRowExpandedChanged(object sender, ASPxGridViewDetailRowEventArgs e)
{
SYSolution_WebUI.ServiceReference.GroupInfo groupInfoModel = (SYSolution_WebUI.ServiceReference.GroupInfo)((ASPxGridView)sender).GetRow(e.VisibleIndex);// 獲取選中行實體
ASPxGridView gv = (ASPxGridView)gvGroup.FindDetailRowTemplateControl(e.VisibleIndex, "gvGroupName"); // 獲取模板內aspxgridView ID名稱
SYSolution_WebUI.ServiceReference.GroupInfo[] model = client.GroupSelUserList("GroupId='" + groupInfoModel.GroupId + "'");// 經過組ID值獲取實體對象
if (model[0].UserInfoList != null && gv != null)// 當用用戶列表值與子aspxgridView不爲空
{
gv.DataSource = model[0].UserInfoList; // 子aspxgridView綁定數據源
gv.DataBind();
}
if (model[0].UserInfoList[0].Name == "") // 若是子aspxgridView中的用戶列表爲空時不顯示 不展開
{
gvGroup.SettingsDetail.AllowOnlyOneMasterRowExpanded = false;
}
}
排序事件中從新綁定數據 BeforeColumnSortingGrouping
protected void gvGroup_BeforeColumnSortingGrouping(object sender, ASPxGridViewBeforeColumnGroupingSortingEventArgs e)
{
gvGroup.DetailRows.CollapseAllRows();// 關閉全部DetailoRow
gvGroup.DetailRows.ExpandRow(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(ASPxGridView1.VisibleRowCount>0) { //ASPxGridView1.Columns[命令列索引] (ASPxGridView1.Columns[4] as GridViewCommandColumn).NewButton.Visible = false; } }