访问母版页中的ASP.NET母版页下拉列表控件';s代码隐藏

访问母版页中的ASP.NET母版页下拉列表控件';s代码隐藏,asp.net,controls,master-pages,code-behind,Asp.net,Controls,Master Pages,Code Behind,我有一个母版页,上面有dropdownlist控件。在上述母版页的代码隐藏中,我希望访问dropdownlist控件并为其分配数据源。以下是母版页的源代码: <section id="login"> <asp:LoginView runat="server" ViewStateMode="Disabled"> ` <AnonymousTemplate> <ul> <asp:Label ID="Label1"

我有一个母版页,上面有dropdownlist控件。在上述母版页的代码隐藏中,我希望访问dropdownlist控件并为其分配数据源。以下是母版页的源代码:

  <section id="login">
<asp:LoginView runat="server" ViewStateMode="Disabled">
` <AnonymousTemplate>
       <ul>
        <asp:Label ID="Label1" runat="server" Text="Report Category"></asp:Label>
        <asp:DropDownList ID="CountriesDropDownList" runat="server"></asp:DropDownList>
      </ul>
    </AnonymousTemplate>

您想访问内容页上的下拉列表,对吗

你可以试试:

this.Master.CountriesDropDownList.DataSource = "myDataSource";

或者检查以下内容:

主代码中创建字符串属性:

public string CountriesDropDownListDataSource
{
    get {
        return this.CountriesDropDownList.DataSource;
    }
    set {
        this.CountriesDropDownList.DataSource= value;
    }
}
要设置数据源,请执行以下操作:

var myMaster = this.Master as YourMasterType;
if(myMaster != null)
{
    myMaster.CountriesDropDownListDataSource = "myDataSource";
}
或者直接从母版页

this.CountriesDropDownListDataSource = "myDataSource";

那么你的问题是什么?您面临的问题是什么?源代码丢失您是否无法在代码背后使用
CountriesDropDownList
?请不要。当我键入此项时,countriesDropDownList不会显示在IntelliSense中,我正在使用visual studio 2013
this.CountriesDropDownListDataSource = "myDataSource";