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

Parsing Nested Grid

6 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sameers
Top achievements
Rank 1
Sameers asked on 05 Jul 2010, 02:00 PM
I have a nested grid, something like this.
                <telerik:RadGrid ID="grdItems" runat="server" GridLines="None" Width="100%">  
                    <ExportSettings> 
                        <Pdf PageWidth="8.5in" PageHeight="11in" PageTopMargin="" PageBottomMargin="" PageLeftMargin="" 
                            PageRightMargin="" PageHeaderMargin="" PageFooterMargin=""></Pdf> 
                    </ExportSettings> 
                    <MasterTableView DataMember="Master" AutoGenerateColumns="False" HierarchyDefaultExpanded="true" 
                        ExpandCollapseColumn-CollapseImageUrl="~/images/trans.gif">  
                        <RowIndicatorColumn Visible="False">  
                            <HeaderStyle Width="20px"></HeaderStyle> 
                        </RowIndicatorColumn> 
                        <ExpandCollapseColumn Visible="False" Resizable="False">  
                            <HeaderStyle Width="20px"></HeaderStyle> 
                        </ExpandCollapseColumn> 
                        <Columns> 
                            <telerik:GridBoundColumn UniqueName="ID" DataField="ID" Visible="false">  
                            </telerik:GridBoundColumn> 
                            <telerik:GridTemplateColumn HeaderText="Package">  
                                <ItemTemplate> 
                                    <asp:DropDownList ID="ddlPackage" runat="server">  
                                    </asp:DropDownList> 
                                    <asp:Label ID="lblOrderItemId" runat="server" Text='<%# Eval("ID") %>' Visible="false"></asp:Label> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn HeaderText="SKU">  
                                <ItemTemplate> 
                                    <asp:HyperLink ID="hypProductID" runat="Server" Text='<%# Eval("ProductId") %>' 
                                        NavigateUrl='<%# "~/Inventory/Product.aspx?id=" & eval("ProductId") %>'></asp:HyperLink> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn HeaderText="Reference">  
                                <ItemTemplate> 
                                    <asp:HyperLink runat="Server" ID="hypeBayItemID" Target="_blank" Text='<%#Eval("eBayItemID")%>'></asp:HyperLink> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn HeaderText="Original Reference" Visible="false">  
                                <ItemTemplate> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn HeaderText="Item">  
                                <ItemTemplate> 
                                    <%#Eval("DisplayName")%> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn HeaderText="Unit Price" Visible="false">  
                                <ItemTemplate> 
                                    <%#FormatCurrency(Eval("AdjustedSitePrice"), 2)%> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn HeaderText="Qty">  
                                <ItemTemplate> 
                                    <%#Eval("Qty")%> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn HeaderText="Subtotal" Visible="false">  
                                <ItemTemplate> 
                                    <%#FormatCurrency( Eval("Qty") * Eval("AdjustedSitePrice"), 2)%> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn HeaderText="Notes" UniqueName="Notes">  
                                <ItemTemplate> 
                                    <%#Eval("Notes")%> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn HeaderText="" Visible="false">  
                                <ItemTemplate> 
                                    <asp:HyperLink ToolTip="Drop Shipped" ID="hypDroppedShipped" ImageUrl="~/images/dropShipped.jpg" 
                                        runat="server" NavigateUrl='<%# "Orders_DropShip.aspx?id=" & Eval("OrderID") %>'></asp:HyperLink> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                        </Columns> 
                        <DetailTables> 
                            <telerik:GridTableView runat="server" DataMember="ChildProducts" AutoGenerateColumns="False" 
                                HierarchyDefaultExpanded="true" ExpandCollapseColumn-CollapseImageUrl="~/images/trans.gif" 
                                Width="100%">  
                                <Columns> 
                                    <telerik:GridBoundColumn UniqueName="OrderItemId" DataField="OrderItemId" Visible="false">  
                                    </telerik:GridBoundColumn> 
                                    <telerik:GridBoundColumn UniqueName="ID" DataField="ID" Visible="false">  
                                    </telerik:GridBoundColumn> 
                                    <telerik:GridTemplateColumn HeaderText="Package">  
                                        <ItemTemplate> 
                                            <asp:DropDownList ID="ddlPackage" runat="server">  
                                            </asp:DropDownList> 
                                            <asp:Label ID="lblBundleOrderItemId" runat="server" Visible="true"></asp:Label> 
                                            <asp:Label ID="lblProductID" runat="server" Text='<%# Eval("ProductID") %>' Visible="false"></asp:Label> 
                                        </ItemTemplate> 
                                    </telerik:GridTemplateColumn> 
                                    <telerik:GridTemplateColumn HeaderText="SKU">  
                                        <ItemTemplate> 
                                            <asp:HyperLink ID="hypProductID" runat="Server" Text='<%# Eval("ProductId") %>' 
                                                NavigateUrl='<%# "~/Inventory/Product.aspx?id=" & eval("ProductId") %>'></asp:HyperLink> 
                                        </ItemTemplate> 
                                    </telerik:GridTemplateColumn> 
                                    <telerik:GridTemplateColumn HeaderText="Item">  
                                        <ItemTemplate> 
                                            <asp:Label ID="lblPRoductName" runat="Server"></asp:Label> 
                                        </ItemTemplate> 
                                    </telerik:GridTemplateColumn> 
                                    <telerik:GridTemplateColumn HeaderText="Qty">  
                                        <ItemTemplate> 
                                            <%#Eval("Qty")%> 
                                        </ItemTemplate> 
                                    </telerik:GridTemplateColumn> 
                                </Columns> 
                            </telerik:GridTableView> 
                        </DetailTables> 
                    </MasterTableView> 
                </telerik:RadGrid> 

On the click of a button, I wanted to save (by getting drop down list in the parent item and that in the child items of the grid).

Here is the code to get controls from the grid.
    Private Sub btnSave_Click(ByVal sender As ObjectByVal e As System.Web.UI.ImageClickEventArgs) Handles btnSave.Click  
        For Each item As Telerik.Web.UI.GridDataItem In Me.grdItems.Items  
            Dim lblOrderItemId As Label = CType(item.FindControl("lblOrderItemId"), Label)  
            Dim ddlPackage As DropDownList = CType(item.FindControl("ddlPackage"), DropDownList)  
              
 
            If lblOrderItemId IsNot Nothing Then 
                'Its main order item  
 
                Dim oi As Orders.OrderItem = OrderServices.OrderItems.GetByID(CInt(lblOrderItemId.Text))  
                oi.PackageID = ddlPackage.SelectedValue  
                OrderServices.OrderItems.Update(oi)  
                'Parse child items  
                Dim grdTable As GridTableView = CType(CType(item.ChildItem, GridNestedViewItem).Cells(1).Controls(0), GridTableView)  
                For Each childItem As Telerik.Web.UI.GridDataItem In grdTable.Items  
                    Dim lblBundleOrderItemId As Label = CType(childItem.FindControl("lblBundleOrderItemId"), Label)  
                    Dim lblProductID As Label = CType(childItem.FindControl("lblProductID"), Label)  
                    ddlPackage = CType(childItem.FindControl("ddlPackage"), DropDownList)  
 
                    
                    
                    
                Next 
 
                'ElseIf lblBundleOrderItemId IsNot Nothing And lblOrderItemId Is Nothing Then  
                '    'Its bundle item  
 
                  
            End If 
        Next 
 
      
       
 
        Session("PackagesMessage") = "Order Shipping Preferences saved." 
        Response.Redirect(Request.Url.PathAndQuery)  
    End Sub 

The values from the master table gets fine, but when it comes to parse the child table, although it get controls fine (lblProductID and lblBundleOrderItemID), but their text propery are empty for some reason. This is also weird that I can see if there are seven bundle items (nested table rows), some of these rows returns good values, but others return empty rows. which is really weird.

Yes, I confirm that ProductID and BundleOrderItemID have values (other than empty string). Of course they do as they are sort of primary keys.

I also tried this from the main loop (instead of GridTableView), but I got the same situation. I can see values displaying on the grid, but I dont get them when I parse via above code.

Any idea? what I might be doing wrong?

thanks,
Sameers

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 Jul 2010, 08:16 AM
 Hello Sameer,

I saw a documentation on "Traversing through details tables/items in Telerik grid". Give a try with same approach described in documentation to access the NestedTableView and see whether it helps.

VB.NET:
 
 Protected Sub btnSave_Click(sender As Object, e As EventArgs) 
        . . . . . . . . . . . . . . . . . . . . . . . . . . 
    Dim grdTable As GridTableView = TryCast(RadGrid1.MasterTableView.Items(item.ItemIndex), GridDataItem).ChildItem.NestedTableViews(0) 
    'access the NestedTableView  
    For Each childItem As Telerik.Web.UI.GridDataItem In grdTable.Items 
        Dim lblBundleOrderItemId As Label = DirectCast(childItem.FindControl("lblBundleOrderItemId"), Label) 
        Dim lblProductID As Label = DirectCast(childItem.FindControl("lblProductID"), Label) 
        ddlPackage = DirectCast(childItem.FindControl("ddlPackage"), DropDownList) 
    Next 
 End Sub 


Hope this helps,
Princy.
0
Sameers
Top achievements
Rank 1
answered on 06 Jul 2010, 08:52 AM
Princy, no difference indeed. I tried that way, but same problem.

I still wonder, why I get values for some items in the child table, and for others, its empty (controls I find via FindControl is NOT NULL, their text property is just empty string).

0
Sameers
Top achievements
Rank 1
answered on 06 Jul 2010, 11:18 AM
I guess I found something weird, causing the issue.

when page post back, some of the child grid's items lose it values. I have created a test project explaining the issue. Please see attached.

  When you load page, you see two main items and every one have about 7 sub items (in child grid). When you click on Save Grid, Notice how 4 out of 7 rows loose all the values and become sort of empty rows.

   I am not sure what is the problem. Using rad grid version Version=2009.3.1314.35 (as defined in the web.config).

   Thanks,
   Sameers

BTW, It seems I can only upload image files here, so if you need sample project which I used to take snapshots from, please tell me how can I upload that.

  
0
Sameers
Top achievements
Rank 1
answered on 08 Jul 2010, 02:30 PM
Is there anyone can response?

It seems that on Postback, some of the controls from the child table lost it values. anyone can tell me why it is happening?

I have a sample project as well, demonstrating the issue.

thanks,
Sameers
0
Sameers
Top achievements
Rank 1
answered on 13 Jul 2010, 08:25 AM
Anyone can tell me why the child grid's some items get vanished on a Postback?
0
Mira
Telerik team
answered on 13 Jul 2010, 12:24 PM
Hello Sameers,

Based on the supplied information, it is hard to determine what is causing the issue.
Please open a formal support ticket and send us a small working project, demonstrating your full setup and showing the unwanted behavior.
We will debug it locally and get back to you.

Thank you in advance for the cooperation.

Best wishes,
Mira
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Sameers
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Sameers
Top achievements
Rank 1
Mira
Telerik team
Share this question
or