0
Answer

Nested datagrids containing checkbox controls

angel 0

angel 0

20y
1.9k
1
Howdy! I am creating a server control that produces a nested datagrid. Each datagrid contains a checkbox column for row selection. Everything populates just fine and sorting works well, but I am having trouble getting a reference to the inner nested datagrid's checkboxes to see what has been selected. The child grids are bound on the ItemDataBound event of the parent grid. I want to get two arrays of datagriditems for both the parent and the child grids of the items that were checked by the user. I can do this with the parent grid, but the child grids are gone at postback. At postback for sorting, the child grids are there and everything is fine. What do I need to do to get a reference to the child grids at postback to see the selected items? Here is my code for the button that posts back to get the selected items: Public Sub OnAddToCart(ByVal sender As Object, ByVal e As EventArgs) Handles Linkbutton1.Click Dim ValArray As New ArrayList Dim dgi As DataGridItem For Each dgi In grid.SelectedItems 'get a reference to the child grid and get it's selected items Dim childgrid As Multigrid = dgi.Cells(1).Controls(1) If Not childgrid Is Nothing Then Dim childDgi As DataGridItem For Each childDgi In childgrid.SelectedItems ValArray.Add(childgrid.DataKeys(childDgi.ItemIndex.ToString())) Next End If Next 'Refresh the datagrid UpdateDataView() End Sub In this code, childgrid is always nothing. When I check the count of controls in cell(1), there's only 1 and it's a label. Any help is greatly appreciated! Barn Chick