Conditinally hide all Child Tables 'Add New Records' Command Item Template Button based on Master Table Column Value

2 posts, 0 answers
  1. gc_0620
    gc_0620 avatar
    246 posts
    Member since:
    Feb 2008

    Posted 21 Aug Link to this post

    Using Telerik .Net Ajax with VS 2015 and 2017.

    Below Telerik Link is my prototype.

    https://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/insert-update-delete-hierarchy/defaultcs.aspx

    In my MasterTableView I have a column named 'IsClosed' which is Bit data type in SQL and is a GridBoundColumn in RadGrid.

    My question is if column 'isClosed' is true in MasterTableView

    1) I would like just to disable 'Add New Records' Commanditem Template Button invisibile to all related GridTableView's but keep 'Refresh'
    CommandItem Template Button's available.

    2) MasterTableView ''Add New Records' Commanditem Template Button should be visible/enabled.

    Thanks a lot

    gc_0620

  2. Eyup
    Admin
    Eyup avatar
    3867 posts

    Posted 26 Aug Link to this post

    Hi,

    Both of these requirements are possible:

    2. The command item can be enabled from here and you probably have this set already in your app:
    <MasterTableView ... CommandItemDisplay="Top">

    1. Now, for the first requirement, there are two options:

    A:
    If the condition is depending on a database value - you can use the ItemDataBound event handler and access the isClosed value of the individual records:
    https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-raw-field-data-and-key-values

    Then, if it is true, you can access the command item using the GetItems method:
    https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/how-to/Common/using-the--getitems-getcolumn-and-getcolumnsafe-methods#items

    Finally, all you need to do is to use the commandItemInstance.FindControl("ID") method to access the buttons and toggle their visibility or enabled state:
    - for refresh button: the ID is RefreshButton
    - for insert button: the ID is AddNewRecordButton

    B:
    If the condition is depending on the checkbox selection made by the user when the item is in edit mode, you can access the CheckBox control using ItemCreated event handler and enable its AutoPostBack property:
    https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-controls-in-editinsert-mode

    Then, you can hook on its change event and in the code behind you can use (sender as CheckBox).Checked to get the condition value. The rest of the process is analogous to the previous step.

    I hope this will prove helpful.

    Regards,
    Eyup
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top