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

Use GridBoundColumn value as DefaultInsertValue for Detail Table

2 Answers 161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ItinerantEngineer
Top achievements
Rank 1
ItinerantEngineer asked on 21 Jan 2019, 06:29 PM

I have a Grid, with a detail table. The Grid datasource has 3 fields, a LineUID, an ItemUID, and an ItemName, and the LineUID is listed in the DataKeyNames.  The detail table displays serial numbers associated with that LineUID.  On an insert to the detail table, the edit form needs to look up available serial numbers based on the ItemUID. Is there a way to:

A) define that the DetailTable GridBoundColumn DefaultInsertValue should be the value of one of the mastertable's columns? Something like

<telerik:GridBoundColumn DataField="RowItemUID" Visible=false DefaultInsertValue=(MasterTable.GetColumnValue("ItemUID"))

 

B) inside the DetailTableDataBind function set the DefaultInsertValue for a column to the value of a non-key value for the mastertable row? Something like

Dim dataItem As GridDataItem = DirectCast(e.DetailTableView.ParentItem, GridDataItem)
Dim itemColumn As DataColumn = e.DetailTableView.Columns.FindByUniqueName("RowItemUID")
itemColumn.DefaultValue = dataItem.GetColumnValue("ItemUID")

2 Answers, 1 is accepted

Sort by
0
Accepted
Eyup
Telerik team
answered on 23 Jan 2019, 06:18 AM
Hello,

I've replied to your query in the support ticket and I suggest that we continue our technical conversation on the mentioned thread. I will also post the response here so that other developers may find it helpful as well:

You can try 2 approaches to achieve this requirement:

1. Your approach mentioned in the forum thread. You can access the parent master item during DetailTableBind:
http://demos.telerik.com/aspnet-ajax/grid/examples/data-binding/programmatic-hierarchy/defaultcs.aspx

Then, you can extract the master key ID using the GetDataKeyValue method:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-raw-field-data-and-key-values

Once you have this ItemUID, you can access the detail column RowItemUID:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/how-to/Common/using-the--getitems-getcolumn-and-getcolumnsafe-methods#columns

You can cast it to GridBoundColumn and set its DefaultInsertValue property to the master ItemUID value.

2. Here is an alternative: generally, you can use the ItemDataBound event handler of the grid and determine whether it is called for the inner detail table using the Name property (GridTableView tag). A condition like if(e.Item.OwnerTableView.Name=="MyInnerTable"){} should do the trick.

For the dropdown specifically, you can use its own DataBinding() event handler, access the detail row using (sender as RadDropDownList).NamingContainer. Then, you can get the DetailTableView using detailItem.OwnerTableView and from there you can access the ParentItem from the master level. Depending on the corresponding master key ID, you can set the DataSource property of the dropdown accordingly and bind it per your own preference.

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.



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.
0
ItinerantEngineer
Top achievements
Rank 1
answered on 04 Feb 2019, 06:33 PM
Sorry for such a late response, project got pulled in a different direction.  I tested out approach #1 with the links you provided on how to get the relevant information and its working great!  Thanks so much for your help.
Tags
Grid
Asked by
ItinerantEngineer
Top achievements
Rank 1
Answers by
Eyup
Telerik team
ItinerantEngineer
Top achievements
Rank 1
Share this question
or