2013-01-04 137 views
0

這似乎應該是一個簡單的答案,但我已經在各處搜索了這一點,似乎無法找到我正在嘗試做的事情,而且我對此很陌生,所以我可能會錯過某些東西希望有人能幫忙。GridView嵌套在DataList中

這樣做的目的是顯示我發送進行維修的掃描儀(dl)的裝箱清單,並且每個維修問題都有筆記(gv)。我能夠正確顯示dl,但我無法獲得gv顯示。即使我硬編碼「問題鍵」。我得到一個對象沒有設置爲對象錯誤。顯然,我不能保留它的硬編碼,所以我嘗試從dl中拉出issuekey(通過DataKey)並將它傳遞給gv,我得到「Index超出範圍」。 (當我通過它時出現-1)。

這是我與....謝謝使用的代碼

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> 
+0

我想我找到我自己的答案.... 在我接着說:onItemDataBound = 「dlShippingList_ItemDataBound」 DataList控件的ASP' VB的我拿出...'把手dlShippingList.ItemDataBound' SOO遠,它似乎是完美的工作! – jharris8567

回答

0

我想我找到我自己的答案....我在加入onItemDataBound =「dlShippingList_ItemDataBound」關於DataList控件的ASP我拿出...手柄dlShippingList.ItemDataBound SOO FAR,它似乎是完美的工作!