none
ObjectDataSource 控件“ObjdsItem”没有命名容器。确保在调用 DataBind 前将控件添加到该页中。 RRS feed

  • 问题

  •  protected void Button1_Click(object sender, EventArgs e)
        {
            //DlstItemList.DataSourceID = "ObjdsDatalist";
            DlstItemList.DataBind();
        }
     <asp:DataList ID="DlstItemList" runat="server" DataSourceID="ObjdsDatalist" 
                                        onitemdatabound="DlstItemList_ItemDataBound">
                                        <ItemTemplate>
                                            <asp:Label ID="LblLabID" runat="server" Text='<%# Eval("LabID") %>' Visible="False" 
                                               ></asp:Label>
                                             <asp:Label ID="LblLabName" runat="server" Text='<%# Eval("LabName") %>' Visible="False" 
                                              ></asp:Label>
                                            
                                            <asp:ObjectDataSource ID="ObjdsItem" runat="server" 
                                                SelectMethod="GetItemInOneLab" TypeName="StudentReservation">
                                                <SelectParameters>
                                                    <asp:ControlParameter ControlID="CourseDropDownList" Name="strTeachTaskNo" 
                                                        PropertyName="SelectedValue" Type="String" />
                                                    <asp:ControlParameter ControlID="LblLabID" Name="strLabID" PropertyName="Text" 
                                                        Type="String" />
                                                    <asp:SessionParameter Name="strUserName" SessionField="UserID" Type="String" />
                                                </SelectParameters>
                                            </asp:ObjectDataSource>
                                            <asp:Panel ID="PnlItem" runat="server" GroupingText="lab">
                                            <asp:GridView ID="GrwItem" runat="server" AutoGenerateColumns="False" 
                                                    CellPadding="5" ondatabound="GrwItem_DataBound" DataSourceID="ObjdsItem" 
                                                    onrowdatabound="GrwItem_RowDataBound" onrowcommand="GrwItem_RowCommand">
                                                 <Columns>
                                                     <asp:BoundField DataField="ItemID" HeaderText="ItemID" InsertVisible="False" 
                                                         SortExpression="ItemID">
                                                         <FooterStyle CssClass="hidden" />
                                                         <HeaderStyle CssClass="hidden" />
                                                         <ItemStyle CssClass="hidden" />
                                                     </asp:BoundField>
                                                     <asp:BoundField DataField="courseName" HeaderText="课程" >
                                                         <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                                         <ItemStyle Wrap="False" />
                                                     </asp:BoundField>
                                                     <asp:BoundField DataField="ItemName" HeaderText="实验项目" SortExpression="ItemName">
                                                         <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                                         <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" Wrap="False" />
                                                     </asp:BoundField>
                                                     <asp:TemplateField HeaderText="是否预约">
                                                         <ItemTemplate>
                                                             <asp:Label ID="IsReserved" runat="server"></asp:Label>
                                                             <asp:Button ID="IWantReserve" runat="server" CommandName="IWantReserve" 
                                                                 Text = "我要预约" onclick="IWantReserve_Click" />                                                             
                                                             <asp:Button ID="btnCancel" runat="server" CommandName="CancelCmd" Text="取消预约"  />
                                                         </ItemTemplate>
                                                         <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                                         <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Wrap="False" />
                                                     </asp:TemplateField>
                                                     <asp:TemplateField HeaderText="时间地点">
                                                         <ItemTemplate>
                                                             <asp:Label ID="lblTimePlace" runat="server" Text="lblTimePlace"></asp:Label>
                                                             <asp:DataList ID="dlArr" runat="server" RepeatColumns="1" 
                                                                 RepeatDirection="Horizontal">
                                                                 <ItemTemplate>
                                                                    <%-- <asp:Label ID="LabelLab" runat="server" Text='<%# Eval("Lab") %>'></asp:Label>--%>
                                                                     <asp:Label ID="lblPlace" runat="server" Text='<%# Eval("Place") %>'></asp:Label>
                                                                     &nbsp;
                                                                     <asp:Label ID="lblTime" runat="server" Text='<%# Eval("Time") %>'></asp:Label>
                                                                 </ItemTemplate>
                                                                 <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" Wrap="False" />
                                                             </asp:DataList>
                                                         </ItemTemplate>
                                                         <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                                         <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Wrap="False" />
                                                     </asp:TemplateField>
                                                     <asp:TemplateField HeaderText="是否完成">
                                                         <ItemTemplate>
                                                             <asp:Label ID="lblIsCompleted" runat="server"></asp:Label>
                                                         </ItemTemplate>
                                                         <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                                         <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Wrap="False" />
                                                     </asp:TemplateField>
                                                     <asp:TemplateField HeaderText="提前几天可以取消预约">
                                                         <ItemTemplate>
                                                             <asp:Label ID="Label1" runat="server"></asp:Label>
                                                         </ItemTemplate>
                                                         <EditItemTemplate>
                                                             <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                                                         </EditItemTemplate>
                                                         <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                                         <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                                     </asp:TemplateField>
                                                     <asp:BoundField DataField="TeachTaskNO" HeaderText="TeachTaskNO" 
                                                         SortExpression="TeachTaskNO">
                                                      <FooterStyle CssClass="hidden" />
                                                         <HeaderStyle  CssClass="hidden" />
                                                         <ItemStyle CssClass="hidden" />
                                                          </asp:BoundField>
                                                 </Columns>      
                                                 <HeaderStyle BackColor="#006699" Height="20px" BorderColor="#999966" 
                                        BorderWidth="1px" ForeColor="White" />
                                             </asp:GridView>
                                            </asp:Panel>
                                        </ItemTemplate>
                                    </asp:DataList>
      <asp:ObjectDataSource ID="ObjdsDatalist" runat="server" 
                                        SelectMethod="GetLabofCourse" TypeName="StudentReservation">
                                        <SelectParameters>
                                            <asp:ControlParameter ControlID="CourseDropDownList" Name="strTeachTaskNo" 
                                                PropertyName="SelectedValue" Type="String" />
                                            <asp:SessionParameter Name="strUserName" SessionField="UserID" Type="String" />
                                        </SelectParameters>
                                    </asp:ObjectDataSource>
    • 已移动 Windie Chai [MVP] 2010年1月25日 0:51 帖不对版 (发件人:Windows Workflow Foundation)
    • 已移动 孟宪会Moderator 2010年1月25日 4:26 (发件人:.NET Framework 一般性问题讨论区)
    2010年1月18日 14:36

全部回复

  • 你好从字面上讲是因为这个控件并没有实现INamingContainer 接口

    你改成<asp:Parameter 试试看
    <asp:ObjectDataSource 
      ID="EmployeeDetailsObjectDataSource" 
      runat="server" 
      TypeName="Samples.AspNet.Controls.NorthwindEmployee" 
      SelectMethod="GetEmployee" 
      UpdateMethod="UpdateEmployee"
      DeleteMethod="DeleteEmployee"
      InsertMethod="InsertEmployee" 
      OnInserted="EmployeeDetailsObjectDataSource_OnInserted" >
      <SelectParameters>
        <asp:Parameter Name="EmployeeID" />  
      </SelectParameters>
      <InsertParameters>
        <asp:Parameter Name="NewEmployeeID" Direction="Output" 
                       Type="Int32" DefaultValue="0" />
      </InsertParameters>
    </asp:ObjectDataSource>
    

    Memory all alone in the moonlight~My Blog in .NET~~~
    2010年1月25日 2:38
    版主