我有以下FormReport.aspx。我想创建一个div class = employeebox>里面的副本。但是当点击addrow_clic时以编程方式?任何帮助将不胜感激
FormReport.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="FormReport.aspx.cs" Inherits="Tardy_Absentee_Report.FormReport" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<style type="text/css">
#headerform
{
height: 56px;
}
#Div1
{
height: 70px;
}
.colum-left
{
width: 122px;
}
.colum-cenleft2
{
width: 344px;
}
.employeebox
{
height: 37px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<fieldset>
<legend>Supervisor information </legend>
<div class="row">
<div class="column-left">Supervisor Name:<span></span> </div>
<div class="column-cenleft">
<asp:TextBox ID="txtsupervisorname" runat="server" Width="103px"></asp:TextBox></div>
<div class="column-cenright"><span>Department:</span></div>
<div class="column-right">
<asp:DropDownList ID="DDownDepartment" runat="server" Height="24px" Width="154px">
</asp:DropDownList>
</div>
</div>
<div class="row">
<div class="column-left">Supervisor Number:<span></span> </div>
<div class="column-cenleft">
<asp:TextBox ID="txtSupervisorNumber" runat="server" Width="103px"></asp:TextBox></div>
<div class="column-cenright"><span>Date of Incident:</span></div>
<div class="column-right">
<asp:TextBox ID="txtDate" runat="server"></asp:TextBox></div>
</div>
</fieldset>
<fieldset>
<legend> Employee Information</legend>
<div id="EmployeeInfo">
<div class="column-left2"><span>Employee Number</span></div>
<div class="column-left2"><span>Employee Name</span></div>
<div class="colum-left2"><span>Reason Code</span></div>
</div>
<div class="employeebox">
<div class="column-left2"><asp:TextBox ID="TextBox4" runat="server"></asp:TextBox></div>
<div class="column-left2">
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox></div>
<div class="column-left2">
<asp:DropDownList ID="DDownResoncode1" runat="server" Width="153px">
</asp:DropDownList>
</div>
</div>
<div class="employeebox">
<div class="column-left2"><asp:TextBox ID="TextBox7" runat="server"></asp:TextBox></div>
<div class="column-left2">
<asp:TextBox ID="TextBox8" runat="server"></asp:TextBox></div>
<div class="column-left2">
<asp:DropDownList ID="DDownResoncode2" runat="server" Height="20px" Width="153px">
</asp:DropDownList></div>
</div>
<div class="employeebox">
<div class="column-left2"><asp:TextBox ID="TextBox10" runat="server"></asp:TextBox></div>
<div class="column-left2">
<asp:TextBox ID="TextBox11" runat="server"></asp:TextBox></div>
<div class="column-left2">
<asp:DropDownList ID="DDownResoncode3" runat="server" Width="153px"></asp:DropDownList>
</div>
</div>
<div class="employeebox">
<div class="column-left2"><asp:TextBox ID="TextBox13" runat="server"></asp:TextBox></div>
<div class="column-left2">
<asp:TextBox ID="TextBox14" runat="server"></asp:TextBox></div>
<div class="column-left2">
<asp:DropDownList ID="DDownResoncode4" runat="server" Height="16px" Width="153px">
</asp:DropDownList>
</div>
</div>
<div style="height: 33px">
<asp:Button ID="addrow" runat="server" Text="AddRow" onclick="addrow_Click" />
</div>
<div>
<asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" />
</div>
</fieldset>
</asp:Content>
FormReport.aspx.cs
protected void addrow_Click(object sender, EventArgs e)
{
TextBox newtextbox = new TextBox();
Panel panel1 = new Panel();
panel1.Controls.Add(panel1);
}
答案 0 :(得分:0)
您可以使用HtmlGenericControl在面板内创建div或在父面板中添加面板
并添加一个样式,你可以使用control.Style.Add(&#34; style&#34;,&#34; value&#34;)
ASPX: 或者您可以使用占位符
C#
protected void addrow_Click(object sender, EventArgs e)
{
Panel pnlEmployeeBox = new Panel();
pnlEmployeeBox.CssClass = "pnlEmployeeBox";
HtmlGenericControl columnLeft2= new HtmlGenericControl("div");
columnLeft2.CssClass = "column-left2";
TextBox txt1 = new TextBox();
columnLeft2.Controls.Add(txt1);
pnlEmployeeBox.Controls.Add(columnLeft2);
columnLeft2 = new HtmlGenericControl("div");
txt1 = new TextBox();
pnlEmployeeBox.Controls.Add(columnLeft2);
// and same goes for the dropdown list
}