I have a repeater control I am using to populate a table. The control works when I populate the repeater with an ObjectDataSource defined in the aspx code and move the header and footers outside the template; HOWEVER, it does not work when I try to bind the repeater datasource to a DataTable in the code behind.
Here's my aspx code:
<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>
My code behind:
panelViewApps.Visible = true;
tblApplicationsTableAdapter app_adapter = new tblApplicationsTableAdapter();
DataTable apps = app_adapter.GetApps("some subset");
repeaterViewApplications.DataSource = apps;
repeaterViewApplications.DataBind();
I also tried it with that last command as Page.Databind()
The adapter method returns the right stuff (as evidenced by the fact that this works when I populate entirely via aspx. The control doesn't show up at all in this case. I've changed variable names - hopefully I haven't introduced irrelevant errors in the process of trying to relate the problem. Note that the code behind is inside a button click and not the load_page() method. (The button click method is being invoked correctly.) Not even the header of the table shows up. When I "view source" on the page, I see the place holder for the panelViewApps - but no table (even an empty table).
Can anyone see what I'm missing?
I have found my own solution. It turns out I need to wrap the DataTable in a 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();