How do I copy an .aspx ListView (including it's LayoutTemplate and ItemTemplate) from the aspx.cs file? The .aspx.cs uses DataBind() to display the values onto the page.
so essentially I want to turn this:
<asp:ListView ID="EvalAnswerList" OnItemDataBound="EvalAnswerList_ItemDataBound" runat="server">
<LayoutTemplate>
<table cellpadding="2" width="640px" border="1" runat="server" class="altRows" id="tblProducts">
<tr id="Tr1" runat="server">
<th id="Th1" runat="server">Question
</th>
</tr>
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="Tr2" runat="server">
<td>
<asp:Label ID="QuestionTextLabel" Font-Bold="true" runat="server" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
Into this:
<asp:ListView ID="EvalAnswerList" OnItemDataBound="EvalAnswerList_ItemDataBound" runat="server">
<LayoutTemplate>
<table cellpadding="2" width="640px" border="1" runat="server" class="altRows" id="tblProducts">
<tr id="Tr1" runat="server">
<th id="Th1" runat="server">Question
</th>
</tr>
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="Tr2" runat="server">
<td>
<asp:Label ID="QuestionTextLabel" Font-Bold="true" runat="server" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<asp:ListView ID="EvalAnswerList" OnItemDataBound="EvalAnswerList_ItemDataBound" runat="server">
<LayoutTemplate>
<table cellpadding="2" width="640px" border="1" runat="server" class="altRows" id="tblProducts">
<tr id="Tr1" runat="server">
<th id="Th1" runat="server">Question
</th>
</tr>
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="Tr2" runat="server">
<td>
<asp:Label ID="QuestionTextLabel" Font-Bold="true" runat="server" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
This copying has to be done in the aspx.cs file. Obviously it won't be exactly like this but I wanted to give you an idea of what I am trying to do. I've tried saying:
ListView test = new ListView();
PlaceHolder.Controls.Add(test);
test = EvalAnswerList;
and then trying to use this in the test.DataBind() but it won't work.