using findcontrol for dropdownlist in a multiview
I have the following multiview set up in my aspx page:
<asp:MultiView id="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View id="View1" runat="server">
<asp:Repeater id="view_program" runat="server">
<ItemTemplate>
blah blah blah
</ItemTemplate>
</asp:Repeater>
</asp:View>
<asp:View id="View2" r开发者_运维技巧unat="server">
<asp:Repeater id="edit_program" runat="server">
<ItemTemplate>
<tr>
<td class="add_border_bold" nowrap>Status</td>
<td width="100%" class="add_border">
<asp:DropDownList id="p_status" runat="server">
</asp:DropDownList>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</asp:View>
</asp:MultiView>
And what I am trying to do, is dynamically fill the dropdown in my page_load function, I have the following code written to do so based on how much I have been able to decipher on findcontrol
DropDownList p_status = View2.FindControl("p_status") as DropDownList;
if (p_status != null)
{
p_status.Items.Add(new ListItem("Green", "Green"));
}
However, when I run the page, and click the button to load up View2 in the MultiView, the dropdown is still completely empty. Any ideas?
The Dropdown is in a repeater, so there can be more than one dropdown.
foreach (RepeaterItem item in edit_program.Items)
{
var ddl = (DropDownList)item.FindControl("p_status");
ddl.Items.Add(new ListItem("Green", "Green"));
}
精彩评论