任何人都可以解釋我如何訪問DevExpress master-detail ASPxGridView?中的一個細節網格選定的行我發現an example on the devexpress support website但我無法得到它拖曳ork,我正在與DevExpress的版本11。ASPxGridView - 如何獲取主/從GridView的詳細網格中的選定行?
在此先感謝。
任何人都可以解釋我如何訪問DevExpress master-detail ASPxGridView?中的一個細節網格選定的行我發現an example on the devexpress support website但我無法得到它拖曳ork,我正在與DevExpress的版本11。ASPxGridView - 如何獲取主/從GridView的詳細網格中的選定行?
在此先感謝。
我找到了一種方法來獲取選定的細節網格的行,不知道如何「建議」這樣做,但它對我來說工作正常,我添加了一個onload()
事件到細節網格,然後我能夠通過將其轉換爲ASPxGridView來訪問該GridView的實例。
這裏是我的代碼,詳細格子:
<Templates>
<DetailRow>
<dx:ASPxGridView ID="detailGrid" runat="server" DataSourceID="SqlDataSource2"
Width="100%" OnBeforePerformDataSelect="detailGrid_DataSelect"
KeyFieldName="InvoiceID"
EnableCallBacks="False"
onload="detailGrid_Load"
>
,然後我處理onoad()
事件是這樣的:
ASPxGridView gridView;
protected void detailGrid_Load(object sender, EventArgs e)
{
gridView = sender as ASPxGridView;
gridView.SelectionChanged += new EventHandler(gridView_SelectionChanged);
}
所以我做了詳細的電網的ASPxGridView實例,現在我可以利用它的SelectionChanged()
事件。
private static int invoiceID;
void gridView_SelectionChanged(object sender, EventArgs e)
{
invoiceID = Convert.ToInt64(gridView.GetSelectedFieldValues("InvoiceID")[0]);
}
在此先感謝user189756答案,因爲它是有用的,但是我想很多人正在進入同一個問題在這裏和因爲以前的答案是不是最新的,因爲它的DevExpress Asp.Net的WebForms的當前版本幾乎是5年前寫的,我只想在這裏增加一個重要的觀點。 爲了處理選擇事件在服務器端,現在你必須ASPxGridView屬性如下指定:
<dx:ASPxGridView ID="MainGrid" runat="server">
<Columns>
<!-- Grid Columns here -->
</Columns>
<Templates>
<DetailRow>
<dx:ASPxGridView ID="DetailGrid" runat="server" KeyFieldName="ID" OnInit="Grid_Init" OnSelectionChanged="Grid_SelectionChanged">
<Columns>
<!-- Grid Columns here -->
</Columns>
<!-- Now the following code is relevant to process Selection Event on Server Side-->
<SettingsBehavior AllowFocusedRow="true"
AllowSelectByRowClick="true"
ProcessFocusedRowChangedOnServer="true"
ProcessSelectionChangedOnServer="true"/>
<SettingsDetail IsDetailGrid="True" />
</dx:ASPxGridView>
</DetailRow>
</Templates>
<SettingsDetail ShowDetailRow="True" />
</dx:ASPxGridView>
通知我使用點擊行選擇,但也有使用複選框另一種變體。所以現在唯一要做的就是在後面的代碼中實現Selection Event Handler。
protected void Grid_SelectionChanged(object sender, EventArgs e)
{
ASPxGridView grid = sender as ASPxGridView;
for (int i = 0; i < grid.VisibleRowCount; i++) // Loop through selected rows
{
if (grid.Selection.IsRowSelected(i)) // do whatever you need to do with selected row values
{
// now use pre-initialized List<object> selectedList to save
selectedList.Add(Convert.ToInt32(grid.GetRowValues(i, "ID")));
}
}
ViewState["SelectedList"] = selectedList;
}
您希望在哪個事件中獲取詳細網格中的選定行? – Akhil 2011-12-28 07:00:52
最好在細節網格的SelectionChanged()事件中,但我甚至無法從我的代碼中訪問我的細節網格,所以我無法真正使用該事件。 – 2011-12-28 07:09:15
究竟什麼不行?事件沒有觸發或...?你能發佈你的代碼嗎? – Filip 2011-12-28 07:55:59