This is a migrated thread and some comments may be shown as answers.

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

1 Answer 17 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 22 Aug 2019, 12:46 AM

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

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 26 Aug 2019, 12:37 PM
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.
Tags
Grid
Asked by
gc_0620
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or