我必须在内容页面中找到一个面板,并且需要在该面板上添加一个下拉列表。我已经搜索过,但我只是将控件添加到母版页.Below是我的代码, 注意:我必须从该页面添加控件而不是从母版页
<%@ 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>
我需要从codebehind为Panel1添加另一个面板。
protected void Page_PreInit(object sender, EventArgs e)
{
//Create a Dynamic Panel
Panel pnlDropDownList;
pnlDropDownList = new Panel();
pnlDropDownList.ID = "pnlDropDownList";
pnlDropDownList.BorderWidth = 1;
pnlDropDownList.Width = 300;
ContentPlaceHolder cph = (ContentPlaceHolder)this.Page.FindControl("ContentPlaceHolder1");
Panel panel = (Panel)cph.FindControl("Panel1");
cph.Controls.Add(pnlDropDownList);
}
答案 0 :(得分:1)
是的,您需要在Master中找到您的控件而不是Page。
如下所示。
public static void Update_to_DB() throws SQLException, IOException {
String URL = "jdbc:ucanaccess://C:\\Users\\bharat.nanwani\\Desktop\\Images.accdb";
Connection conn = DriverManager.getConnection(URL);
//Statement stmt = conn.createStatement();
PreparedStatement p;
File ImgPath = new File("C:\\Users\\bharat.nanwani\\Desktop\\Desert.jpg");
FileInputStream fin = new FileInputStream(ImgPath);
String query = "INSERT INTO Images(Data) VALUES(?);";
p = conn.prepareStatement(query);
p.setBinaryStream(1, fin);
p.execute();
}
public static void update_to_DISK() throws SQLException, IOException {
String URL = "jdbc:ucanaccess://C:\\Users\\bharat.nanwani\\Desktop\\Images.accdb";
Connection conn = DriverManager.getConnection(URL);
PreparedStatement p;
ResultSet rs;
String query = "SELECT Data FROM Images";
p = conn.prepareStatement(query);
rs = p.executeQuery();
if (rs.next()) {
byte[] bytearray = rs.getBytes("Data");
FileOutputStream fos = new FileOutputStream("C:\\Users\\bharat.nanwani\\Desktop\\New Folder\\test.jpg");
fos.write(bytearray);
fos.close();
System.out.println(bytearray);
}
}
这应该有效。
答案 1 :(得分:0)
在面板中添加一个PlaceHolder控件,希望在aspx页面中添加新的DropDownList面板
<asp:Panel ID="Panel1" runat="server">
<asp:PlaceHolder ID="placeholder1" runat="server"></PlaceHolder>
</asp:Panel>
在后面的代码中,要将控件添加到页面使用:
placeholder1.Controls.add(pnlDropDownList);
答案 2 :(得分:-3)
我无法理解为什么不添加像这样的控件
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
<asp:Panel ID="Panel1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
</asp:Panel>
</asp:ContentPlaceHolder>