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 2019 Link to this post

    Using Telerik .Net Ajax with VS 2015 and 2017.

    Below Telerik Link is my prototype.

    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


  2. Eyup
    Eyup avatar
    3953 posts

    Posted 26 Aug 2019 Link to this post


    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:

    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:

    Then, if it is true, you can access the command item using the GetItems method:

    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

    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:

    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.

    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