Search code examples
asp.netvb.netgridviewnesteddatalist

GridView Nested inside DataList


This seems like it should be an easy answer, but I have searched everywhere for this and can't seem to find what I am trying to do and i'm new to this so I might be missing something... Hopefully someone can help.

The purpose of this is to display a packing list of scanners (the dl) I am sending for repair and each repair issue has notes (the gv). I am able to get the dl to display correctly, but i can't get the gv to display at all. Even when i hard code the "issuekey". I get an Object not set to object error. Obviously i can't keep it hard coded, so I try to pull the issuekey (via a DataKey)from the dl and pass it to the gv, I get "Index was out of range". (when i step thru it comes up -1).

Here is the code i'm working with.... THANKS

Sub LoadShippingList()
    dlShippingList.DataSource = WarehouseManager.GetScannerIssuesByScannerStatus(WarehouseManager.ScannerStatus.PendingShipForRepair)
    dlShippingList.DataBind()
End Sub

Protected Sub dlShippingList_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlShippingList.ItemDataBound
    Dim dList As DataList = CType(sender, DataList)
    Dim intScannerIssueKey As Integer = dList.DataKeys(e.Item.ItemIndex)

    Dim gv As GridView
    gv = CType(e.Item.FindControl("gvShippingListIssueNotes"), GridView)
    gv.DataSource() = WarehouseManager.GetScannerIssueNotes(intScannerIssueKey)
    gv.DataBind()

End Sub


<asp:Panel ID="pnlShippingList" runat="server">
            <asp:Label ID="lblShippingListCaption" runat="server" Text="Shipping List" SkinID="PageTitle"></asp:Label>
            <br />
            <asp:DataList ID="dlShippingList" runat="server" GridLines="Both" DataKeys="ScannerIssueKey" DataKeyField="ScannerIssueKey">
                <HeaderTemplate>
                    <table>
                        <tr>
                            <td>
                                <asp:Label ID="lblShipmentNumberCaption" runat="server" Text="Shipment:" SkinID="FieldLabel"></asp:Label>
                            </td>
                            <td>
                                <asp:Label ID="lblShipmentNumber" runat="server" SkinID="FeedbackMessageSmallDark"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:Label ID="lblShipmentDateCaption" runat="server" Text="Date:" SkinID="FieldLabel"></asp:Label>
                            </td>
                            <td>
                                <asp:Label ID="ShipmentDate" runat="server" SkinID="FeedbackMessageSmallDark"></asp:Label>
                            </td>
                        </tr>
                    </table>
                </HeaderTemplate>
                <ItemTemplate>
                    Issue #:<asp:Label ID="lblScannerIssueKey" runat="server" Text='<%# Eval("ScannerIssueKey") %>'></asp:Label>
                    Scanner #:
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("ScannerKey") %>'></asp:Label>
                    Subject:<asp:Label ID="Label2" runat="server" Text='<%# Eval("IssueDescription") %>'></asp:Label>
                    <br />
                    Notes:<br />
                    <asp:GridView ID="gvShippingListIssueNotes" HorizontalAlign="Left" runat="server"
                        Font-Size="Medium" EmptyDataText="No Notes" AutoGenerateColumns="false" SkinID="SimpleGrid">
                        <RowStyle VerticalAlign="Top" HorizontalAlign="Center" />
                        <Columns>
                            <asp:BoundField HeaderText="Notes" DataField="Notes" />
                            <asp:BoundField HeaderText="User" DataField="UserEntered" />
                            <asp:BoundField HeaderText="Date" DataField="DateAndTime" />
                        </Columns>
                    </asp:GridView>
                    <br />
                </ItemTemplate>
                <FooterTemplate>
                    Weissmans's 6750 Manchester Avenue St. Louis MO 63139</FooterTemplate>
            </asp:DataList>
            <br />
        </asp:Panel>

Solution

  • I THINK I FOUND MY OWN ANSWER.... in the ASP of the DataList I added onItemDataBound="dlShippingList_ItemDataBound" on vb i took out ... Handles dlShippingList.ItemDataBound SOO FAR, it seems to be working perfectly!