下拉列表在预渲染时丢失其项集合

本文关键字:集合 下拉列表 | 更新日期: 2023-09-27 18:32:27

我的设计中得到了以下结构:

UpdatePanel,在它里面是一个AjaxTabContainer,在它里面是一个AjaxTabPanel,在它里面是一个ASP FormView,最后在它里面是一个Drop Down List

我的应用程序是使用 3 层体系结构创建的,我的下拉列表的数据源实际上是业务逻辑类返回的数据表。

我的问题:

  • 加载页面后,我的下拉列表不显示任何数据。

我的试验:

  • 我在下拉列表中创建了两个事件"OnDataBound"和"OnPreRender"来检查我丢失数据的位置。

  • 调试模式下,在数据绑定时,我发现下拉列表的列表集合存在

  • 但是,在预呈现时,下拉列表显示"不存在枚举"并且不存在集合。

我的代码:

我有以下选项卡控件设计

 <asp:UpdatePanel ID="UpdtPnlRefugeeInfo" runat="server">
     <ContentTemplate>
          <ajaxcontrol:TabContainer ID="tabInfoPanel" runat="server" Style="visibility: visible;">
              <ajaxcontrol:TabPanel runat="server" ID="PnlBasicInfo">
               <HeaderTemplate>
                Basic Info
               </HeaderTemplate>
               <ContentTemplate>
                     <asp:FormView runat="server" ID="FormViewBasicInfo" DataSourceID="SQLInfoDashboard" OnDataBound="FormViewBasicInfo_DataBound" Width="100%">
                           <ItemTemplate>
                                <table runat="server" id="EditTable" style="width: 100%">
                                    <tr>
                                        <td class="mytdlabel">
                                            <asp:Label CssClass="mylabel" runat="server" ID="lblGender" Text="Gender"></asp:Label>
                                        </td>
                                         <td class="mytddata">
                                               <asp:DropDownList CssClass="mydropdown" ID="DDLGender" runat="server" OnDataBound="DDLGender_DataBound" OnPreRender="DDLGender_PreRender"></asp:DropDownList>
                                          </td>

代码隐藏:

     protected void Page_Load(object sender, EventArgs e)
    {
        BLREOptions = new BusinessLogic.BLREOptions(); // this is my business logic class 

        DDLGender = ((DropDownList)FormViewBasicInfo.FindControl("DDLGender"));

        tabInfoPanel.ActiveTab = tabInfoPanel.Tabs[0];
        FormViewBasicInfo.DataBind();

        LoadDDLs();
    }
        protected void LoadDDLs()
    {
        DDLGender.DataSource = BLREOptions.getGenderList();
        DDLGender.DataValueField = "OptionValue";
        DDLGender.DataTextField = "OptionName";
        DDLGender.DataBind();
    }
    protected void DDLGender_DataBound(object sender, EventArgs e)
    {
           // The List is found here 
    }
    protected void DDLGender_PreRender(object sender, EventArgs e)
    {
           // the list is not found here
    }

下拉列表在预渲染时丢失其项集合

我在 Kb 的部分答案中找到了解决方案。

我将 DDL 的绑定添加到 FormView 数据绑定事件,它工作正常。