Skip to content

Рandle the grid's DetailRowGetButtonVisibility event to hide the detail button for empty detail rows.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/asp-net-web-forms-grid-hide-detail-button-for-empty-detail-rows

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid View for ASP.NET Web Forms - How to hide the detail button when the detail grid is empty

This example demonstrates how to handle the grid's DetailRowGetButtonVisibility event to hide the detail button for empty detail rows.

Hide detail button for empty detail rows

Overview

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;
}

Files to Review

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Рandle the grid's DetailRowGetButtonVisibility event to hide the detail button for empty detail rows.

Topics

Resources

License

Stars

Watchers

Forks