I have the same problem. I am unable to find a control inside the ListView template InsertItemTemplate. Below is small test case. When I click the button MyButton, I want to make the panel HiddenPanel visible.
<
asp:ListView ID="MyListView" runat="server"
InsertItemPosition="LastItem"
DataSourceID="MySQL" DataKeyNames="id">
<LayoutTemplate><p />ABC
<asp:PlaceHolder runat="server" ID="itemPlaceHolder">
</asp:PlaceHolder><p />XYZ
</LayoutTemplate>
<ItemTemplate>x</ItemTemplate>
<InsertItemTemplate><p />INSERT
<asp:Button ID="MyButton" runat="server"
Text="Button" OnClick="MyButton_Click" />
<asp:Panel ID="HiddenPanel" runat="server" Visible="false">
Hello World!
</asp:Panel></InsertItemTemplate>
</
asp:ListView>
<
asp:SqlDataSource ID="MySQL" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnStr %>"SelectCommand="SELECT * FROM [MySQLTable]">
</
asp:SqlDataSource>
I have tried various ways to parse the asp.net control tree DOM but so far I cannot find the panel object to change Visible=true. Here are two methods I have tried.
protected void MyButton_Click(object sender, EventArgs e)
{
Panel p1 = MyListView.FindControl("HiddenPanel") as Panel;
if (p1 != null)p1.Visible = true;for (int i = 0; i <= MyListView.Items.Count - 1; i++)
{
Panel p2 = MyListView.Items[i].FindControl("HiddenPanel") as Panel;if (p2 != null)p2.Visible = true;
}
}
How can I find controls with the InsertItemTemplate when a button is clicked?