我有一个下拉列表:
<asp:DropDownList ID="ddlGoalKeeper" runat="server">
</asp:DropDownList>
一个可爱的小家伙。我有一些代码可以找到它:
DropDownList myControl1 = (DropDownList)Page.FindControl("ddlGoalKeeper");
不是..只是我的 myControl1
没有设置...所以当我稍后在我的代码中尝试将 visible 设置为 true 时,它不起作用。
有什么想法吗?
最佳答案
我遇到过它不起作用的一个原因是如果控件是在网站使用母版页时。
您可以使用这个想法首先获取对母版页的引用,然后从内容页获取正确的控件:
ContentPlaceHolder MainContent = Page.Master.FindControl("MainContent") as ContentPlaceHolder;
DropDownList myControl1 = (DropDownList)MainContent.FindControl("ddlGoalKeeper");
关于c# - FindControl - 找不到下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8324994/