This example demonstrates how to handle the grid's DetailRowGetButtonVisibility
event to hide the detail button for empty detail rows.
Create a master grid control, set its ShowDetailRow property to true
, specify the grid's Templates.DetailRow property, and add a detail grid to the template.
<dx:ASPxGridView ID="mainGrid" runat="server" AutoGenerateColumns="False" DataSourceID="masterDataSource"
KeyFieldName="CategoryID" OnDataBinding="masterGrid_DataBinding"
OnDetailRowGetButtonVisibility="masterGrid_DetailRowGetButtonVisibility">
<Templates>
<DetailRow>
<dx:ASPxGridView ID="detailGrid" runat="server" KeyFieldName="ProductID" DataSourceID="dsDetail"
AutoGenerateColumns="False" OnBeforePerformDataSelect="detailGrid_BeforePerformDataSelect" >
<!-- ... -->
</dx:ASPxGridView>
</DetailRow>
</Templates>
<Columns>
<!-- ... -->
</Columns>
<SettingsDetail ShowDetailRow="True" />
</dx:ASPxGridView>
Handle the master grid's server-side DataBinding event. In the handler, create a select command and check whether the detail data source contains the corresponding fields. Save the resulting rows to the session (SelectResult).
protected void masterGrid_DataBinding (object sender, EventArgs e) {
DoSelect(masterDataSource.DataFile);
}
private void DoSelect (string connectionString) {
DataView selectResult = new DataView();
string selectCommand = "select distinct [CategoryID] from [Products]";
using (AccessDataSource ds = new AccessDataSource(connectionString, selectCommand)) {
selectResult = (DataView)ds.Select(DataSourceSelectArguments.Empty);
}
ArrayList result = new ArrayList();
foreach (DataRow row in selectResult.Table.Rows)
result.Add(row["CategoryID"]);
Session["SelectResult"] = result;
}
Handle the grid's server-side DetailRowGetButtonVisibility event. Based on the row's key value, determine whether the corresponding detail row is empty and set the e.ButtonState argument property to Hidden
to hide the detail button dor empty detail rows.
protected void masterGrid_DetailRowGetButtonVisibility (object sender, ASPxGridViewDetailRowButtonEventArgs e) {
if (!((ArrayList)Session["SelectResult"]).Contains(e.KeyValue))
e.ButtonState = GridViewDetailRowButtonState.Hidden;
}
- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx.vb)
(you will be redirected to DevExpress.com to submit your response)