【问题标题】:asp.net repeater control not showing up with table, datasource defined in code behindasp.net 转发器控件未显示在表中,数据源在后面的代码中定义
【发布时间】:2013-11-20 18:38:20
【问题描述】:

我有一个用来填充表格的中继器控件。当我使用在 aspx 代码中定义的 ObjectDataSource 填充转发器并将页眉和页脚移到模板外时,该控件起作用;但是,当我尝试将转发器数据源绑定到后面代码中的 DataTable 时,它​​不起作用。

这是我的 aspx 代码:

   <asp:Panel ID="panelViewApps" runat="server">
          <asp:Repeater ID="repeaterViewApplications" runat="server">
          <HeaderTemplate>
            <table class="items">
                <tr>
                <td><div align="center"><font color="#666666" size="2" face="Arial, Helvetica, sans-serif">Date</font></div></td>
                <td><div align="center"><font color="#666666" size="2" face="Arial, Helvetica, sans-serif">Number</font></div></td>
                <td><div align="center"><font color="#666666" size="2" face="Arial, Helvetica, sans-serif">Name</font></div></td>
                </tr>
          </HeaderTemplate>

          <ItemTemplate>
               <tr>
               <td><div align="center"><font color="#666666" size="2" face="Arial, Helvetica, sans-serif">
                    <%# DataBinder.Eval(Container.DataItem, "Application_Date") %></font></div></td>
               <td> something else </td>
               <td> something else </td>
               </tr>  
          </ItemTemplate>

          <FooterTemplate>
            </table>
          </FooterTemplate>
        </asp:Repeater>
   </asp:Panel>

我的代码:

panelViewApps.Visible = true;     
tblApplicationsTableAdapter app_adapter = new tblApplicationsTableAdapter();
DataTable apps = app_adapter.GetApps("some subset");
repeaterViewApplications.DataSource = apps;
repeaterViewApplications.DataBind();

我还尝试了最后一个命令为 Page.Databind()

适配器方法返回正确的东西(事实证明,当我完全通过 aspx 填充时,这可以工作。在这种情况下,控件根本不会出现。我已经更改了变量名 - 希望我没有t 在尝试关联问题的过程中引入了不相关的错误。请注意,后面的代码是在按钮单击内部,而不是 load_page() 方法。(正确调用了按钮单击方法。)甚至没有表头出现。当我在页面上“查看源代码”时,我看到 panelViewApps 的占位符 - 但没有表格(甚至是空表格)。

谁能看到我错过了什么?

【问题讨论】:

    标签: asp.net html-table datasource repeater


    【解决方案1】:

    我找到了自己的解决方案。事实证明,我需要将 DataTable 包装在 DataView 中。

    panelViewApps.Visible = true;     
    tblApplicationsTableAdapter app_adapter = new tblApplicationsTableAdapter();
    DataTable apps = app_adapter.GetApps("some subset");
    //need to use a DataView instead of the DataTable directly
    DataView apps_view = new DataView(apps);
    repeaterViewApplications.DataSource = apps_view;
    repeaterViewApplications.DataBind();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多