Here is a simple example.
ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Test._Default" %> <%@ Register Assembly="DevExpress.Web.v12.2, Version=12.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %> <%@ Register Assembly="DevExpress.Web.v12.2, Version=12.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form" runat="server"> <script language="javascript" type="text/javascript"> function OnGetSelectedFieldValues(selectedValues) { alert(selectedValues); } </script> <dx:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" DataSourceID="masterDataSource" KeyFieldName="ID" Width="100%"> <Columns> <dx:GridViewDataColumn FieldName="Name" Caption="名称" /> </Columns> <Templates> <DetailRow> <dx:ASPxGridView ID="detailGrid" runat="server" KeyFieldName="ID" Width="100%" ClientInstanceName="dgdv" OnInit="detailGrid_Init"> <Columns> <dx:GridViewCommandColumn ShowSelectCheckbox="True"> <HeaderTemplate> <dx:ASPxCheckBox ID="SelectAllCheckBox" runat="server" ToolTip="Select/Unselect all rows on the page" ClientSideEvents-CheckedChanged="function(s, e) { dgdv.SelectAllRowsOnPage(s.GetChecked()); }" /> </HeaderTemplate> <HeaderStyle HorizontalAlign="Center" /> </dx:GridViewCommandColumn> <dx:GridViewDataColumn FieldName="Name" Caption="名称" /> </Columns> <SettingsBehavior AllowSelectByRowClick="true" /> </dx:ASPxGridView> </DetailRow> </Templates> <SettingsDetail ShowDetailRow="true" AllowOnlyOneMasterRowExpanded="true" /> </dx:ASPxGridView> <dx:ASPxButton ID="btnTest" runat="server" Text="Test"> <ClientSideEvents Click="function(s, e){ dgdv.GetSelectedFieldValues('ID', OnGetSelectedFieldValues); e.processOnServer = false; }" /> </dx:ASPxButton> <asp:SqlDataSource ID="masterDataSource" runat="server" DataSourceMode="DataReader" ConnectionString="<%$ ConnectionStrings:TestConn%>" SelectCommand="SELECT * FROM Line"></asp:SqlDataSource> </form> </body> </html>
CS
using DevExpress.Web.ASPxEditors; using DevExpress.Web.ASPxGridView; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Test { public partial class _Default : System.Web.UI.Page { protected void detailGrid_Init(object sender, EventArgs e) { ASPxGridView dgrid = sender as ASPxGridView; if (dgrid == null) return; var dataFileId = (int)(sender as ASPxGridView).GetMasterRowFieldValues("ID"); DataTable table = new DataTable(); SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["TestConn"].ConnectionString); conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = string.Format("select * from Main where LineID={0}", dataFileId); SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.Fill(table); conn.Close(); dgrid.DataSource = table; dgrid.DataBind(); } } }