Giter Club home page Giter Club logo

asp-net-web-forms-grid-specify-command-button-settings's Introduction

GridView for ASP.NET Web Forms - How to specify the settings of built-in and custom command buttons based on a condition

This example demonstrates how to handle the grid's CommandButtonInitialize and CustomButtonInitialize events to specify the visibility of built-in and custom command buttons.

Buttons

Overview

Follow the steps below:

  1. Create the Grid View control, populate it with columns, and bind it to a data source. Add a GridViewCommandColumn and enable its ShowEditButton, ShowNewButton, and ShowDeleteButton properties to display built-in command buttons. Use the column's CustomButtons property to create a custom command button.

    <dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" KeyFieldName="ProductID"
        DataSourceID="AccessDataSource1" OnCommandButtonInitialize="ASPxGridView1_CommandButtonInitialize"
        OnCustomButtonInitialize="ASPxGridView1_CustomButtonInitialize">
        <!-- ... -->
        <Columns>
            <dx:GridViewCommandColumn VisibleIndex="0" ShowEditButton="True" ShowNewButton="True"
                ShowDeleteButton="True">
                <CustomButtons>
                    <dx:GridViewCommandColumnCustomButton ID="btnCustom" Text="CustomButton" />
                </CustomButtons>
            </dx:GridViewCommandColumn>
            <!-- ... -->
        </Columns>
    </dx:ASPxGridView>
    <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/nwind.mdb"
        <!-- ... --
    </asp:AccessDataSource>
  2. Handle the grid's server-side CommandButtonInitialize event. In the handler, use the ButtonType and Visible argument properties to identify a particular command button and specify its visibility based on a custom criteria.

    protected void ASPxGridView1_CommandButtonInitialize(object sender, ASPxGridViewCommandButtonEventArgs e) {
        if (e.VisibleIndex == -1) return;
    
        switch (e.ButtonType) {
            case ColumnCommandButtonType.Edit:
                e.Visible = EditButtonVisibleCriteria((ASPxGridView)sender, e.VisibleIndex);
                break;
            case ColumnCommandButtonType.Delete:
                e.Visible = DeleteButtonVisibleCriteria((ASPxGridView)sender, e.VisibleIndex);
                break;
        }
    }
    
    private bool EditButtonVisibleCriteria(ASPxGridView grid, int visibleIndex) {
        // ...
    }
    private bool DeleteButtonVisibleCriteria(ASPxGridView grid, int visibleIndex) {
        // ...
    }
  3. Handle the grid's server-side CustomButtonInitialize event. In the handler, use the ButtonID and Visible argument properties to identify the custom command button and specify its visibility based on a condition.

    protected void ASPxGridView1_CustomButtonInitialize(object sender, ASPxGridViewCustomButtonEventArgs e) {
        if (e.VisibleIndex == -1) return;
    
        if (e.ButtonID == "btnCustom" && e.VisibleIndex % 2 != 0)
            e.Visible = DefaultBoolean.False;
    }

Files to Review

Documentation

Does this example address your development requirements/objectives?

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

asp-net-web-forms-grid-specify-command-button-settings's People

Contributors

devexpressexamplebot avatar elenapeskova avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.