Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在内容页中添加面板?_C#_Asp.net - Fatal编程技术网

C# 如何在内容页中添加面板?

C# 如何在内容页中添加面板?,c#,asp.net,C#,Asp.net,我必须在内容页中找到一个面板,并需要在该面板上添加下拉列表。我已经搜索了,但我只找到了用于向母版页添加控件的下拉列表。下面是我的代码, 注意:我必须从该页本身而不是母版页添加控件 <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Salesorder.aspx.cs" Inherits="Salesorder" %> <as

我必须在内容页中找到一个面板,并需要在该面板上添加下拉列表。我已经搜索了,但我只找到了用于向母版页添加控件的下拉列表。下面是我的代码, 注意:我必须从该页本身而不是母版页添加控件

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Salesorder.aspx.cs" Inherits="Salesorder" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <script src="assets/plugins/jquery-1.10.2.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
  <div class="row">
<asp:Panel ID="Panel1" runat="server"> 
</asp:Panel>             
        </div>
</asp:Content>

我不明白你为什么不添加这样的控件

<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
        <asp:Panel ID="Panel1" runat="server">
            <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
        </asp:Panel>
    </asp:ContentPlaceHolder>

我不明白你为什么不添加这样的控件

<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
        <asp:Panel ID="Panel1" runat="server">
            <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
        </asp:Panel>
    </asp:ContentPlaceHolder>

是的,您需要在母版而不是页面中查找控件

如下图所示

ContentPlaceHolder cph = (ContentPlaceHolder)this.Master.FindControl("ContentPlaceHolder1");

这应该可以工作。

是的,您需要在母版而不是页面中找到控件

如下图所示

ContentPlaceHolder cph = (ContentPlaceHolder)this.Master.FindControl("ContentPlaceHolder1");

这应该可以工作。

在面板中添加占位符控件,以便在aspx页面中添加新的DropDownList面板

<asp:Panel ID="Panel1" runat="server"> 
    <asp:PlaceHolder ID="placeholder1" runat="server"></PlaceHolder>
</asp:Panel>

在希望在aspx页面中添加新DropDownList面板的面板中添加占位符控件

<asp:Panel ID="Panel1" runat="server"> 
    <asp:PlaceHolder ID="placeholder1" runat="server"></PlaceHolder>
</asp:Panel>


您可以向我们展示您正在尝试使用的C代码吗?受保护的无效页面\u PreInit(对象发送方,事件参数){//创建动态面板面板pnlDropDownList;pnlDropDownList=new Panel();pnlDropDownList.ID=“pnlDropDownList”;pnlDropDownList.BorderWidth=1;pnlDropDownList.Width=300;ContentPlaceHolder cph=(ContentPlaceHolder)this.Page.FindControl(“ContentPlaceHolder 1”);Panel Panel=(Panel)cph.FindControl(“Panel1”);cph.Controls.Add(pnlDropDownList);}我在“cph”中添加了一个代码@codeek不添加pnlDropDownList。将其添加到“面板”中。顺便说一句,你为什么要在单独的面板中添加dropdownlist?@Priya,不,对不起,我不会这么做。你可以参考。注意:只需创建一个dropdownlist控件实例,并将其添加到带有Panel1.Controls.add(dropdownlistInstance)的Panel1中,您可以向我们展示您正在尝试使用的C代码吗?受保护的void Page_PreInit(object sender,EventArgs e){//创建一个动态面板Panel pnlDropDownList;pnlDropDownList=new Panel();pnlDropDownList.ID=“pnlDropDownList”;pnlDropDownList.BorderWidth=1;pnlDropDownList.Width=300;ContentPlaceHolder cph=(ContentPlaceHolder)this.Page.FindControl(“ContentPlaceHolder 1”);Panel=(Panel)cph.FindControl(“Panel1”);cph.Controls.Add(pnlDropDownList);}我在“cph”中添加了一个代码@Codeekdon't add pnlDropDownList。将其添加到“面板”中。顺便说一句,你为什么要在单独的面板中添加dropdownlist?@Priya,不,对不起,我不会这么做。你可以参考。注意:只需创建一个dropdownlist控件实例,并使用Panel1.Controls将其添加到Panel1中。add(dropdownlistInstance)OP不喜欢添加dropdownlist,请仔细阅读问题。@ruken aslan,根据用户需要,每当单击按钮时,我都必须创建一个下拉列表。对于我的回答,我感到抱歉。我最好仔细阅读问题@priya@DenishParvadia-O Deni@Codeek,实际上我只从该网站获取了代码。正常页面而不是母版和内容页面可以正常工作。请任何人帮助meOP都不要添加下拉列表,请仔细阅读问题。@ruken aslan,我必须创建一个下拉列表每当按钮被点击时,根据用户的需要。我很抱歉我的答案。我最好仔细阅读问题@priya@DenishParvadia-O Deni@Codeek,事实上我只从那个网站上获取了代码。正常页面工作正常,而不是母版和内容页面。请任何人帮助我也尝试过它的工作,但控件名太长。然后选择dropdownlist的dex属性不触发。哪个控件,下拉列表?或者控件名称或id?Dropdownlist控件名称您需要如何处理dropdownlost,并且它是动态生成的na?我也尝试过这样做,但控件名称太长..然后选择Dropdownlist的索引属性不触发。哪个控件,Dropdownlist?或者控件名称或id?Dropdownlist控件名称您需要如何处理dropdownlost,它是动态生成的吗?