2014-01-21 3 views
0

TextBox 1 개와 버튼 1 개가 있습니다. 사용자가 텍스트 상자에 5를 입력하고 예를 들어 버튼을 클릭하면 5 div을 표시하려고합니다.TextBox 대신 div를 표시합니다. C#

나는 이것을 가지고 있지만

protected void Button1_Click(object sender, EventArgs e) 
{ 
    int NumberOfTextBoxes = Convert.ToInt32(TextBox_UserEntry.Text); 
    for (int i = 0; i < NumberOfTextBoxes; i++) 
    { 
     TextBox tb = new TextBox(); 
     tb.ID = "tb" + Convert.ToInt32(i + 1); 
     Panel1.Controls.Add(tb); 
    } 
} 

당신이 날

TextBox tb = new TextBox(); 
tb.ID = "tb" + Convert.ToInt32(i + 1); 
Panel1.Controls.Add(tb); 

   <asp:TextBox ID="TextBox_UserEntry" runat="server"></asp:TextBox> 
       <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> 
       <asp:Panel ID="ParentPanel" runat="server"> 
       </asp:Panel> 

div에 DIV를 변경하는 데 도움이 될 수는 div에 할 수 있도록하는 방법을 모른다

   <div id="divOccupantProfile"> 

       <asp:Label ID="OPfamilyname" runat="server" Text="Family Name"></asp:Label> 
       <asp:TextBox ID="textOPfamilyname" runat="server"></asp:TextBox><br /> 

       <asp:Label ID="OPfirstname" runat="server" Text="First Name"></asp:Label> 
       <asp:TextBox ID="textOPfirstname" runat="server"></asp:TextBox><br /> 

       <asp:Label ID="OPmiddlename" runat="server" Text="Middle Name"></asp:Label> 
       <asp:TextBox ID="textOPmiddlename" runat="server"></asp:TextBox><br /> 

       <asp:Label ID="OPmaritalstatus" runat="server" Text="Marital Status"></asp:Label> 
       <asp:DropDownList ID="ddlOPmaritalstatus" runat="server" > 
        <asp:ListItem></asp:ListItem> 
        <asp:ListItem>Married</asp:ListItem> 
        <asp:ListItem>Single</asp:ListItem> 
        <asp:ListItem>Divorced</asp:ListItem> 
       </asp:DropDownList><br /> 

       <asp:Label ID="OPoccupation" runat="server" Text="Occupation"></asp:Label> 
       <asp:TextBox ID="textOPoccupation" runat="server"></asp:TextBox><br /> 

       <asp:Label ID="OPrelationship" runat="server" Text="Relationship"></asp:Label> 
       <asp:DropDownList ID="ddlOPrelationship" runat="server" > 
        <asp:ListItem></asp:ListItem> 
        <asp:ListItem>Wife</asp:ListItem> 
        <asp:ListItem>Daughter</asp:ListItem> 
        <asp:ListItem>Son</asp:ListItem> 
        <asp:ListItem>Father</asp:ListItem> 
        <asp:ListItem>Mother</asp:ListItem> 
        <asp:ListItem>House helper</asp:ListItem> 
        <asp:ListItem>Driver</asp:ListItem> 
       </asp:DropDownList> 

       </div> 
+0

ASP.NET WebForms이 좋으시겠습니까? –

+0

예 @SergeyBerezovskiy 예 : @SergeyBerezovskiy –

답변

1

이 목적으로 Panel을 사용할 수 있습니다. Div으로 렌더링됩니다.

int NumberOfDiv = Convert.ToInt32(TextBox_UserEntry.Text); 
for (int i = 0; i < NumberOfDiv; i++) 
{ 
    Panel pnl = new Panel(); 
    pnl.ID = "pnl" + Convert.ToInt32(i + 1); 
    ParentPanel.Controls.Add(pnl); 
} 
+0

'ParentPanel'은 ID입니다. 오류가 발생했습니다. –

+0

'Panel1'의 이름을 'ParentPanel'로 바꾸거나'Panel1'로 바꿉니다. – Arshad

+0

오 죄송합니다. asp 코드를 입력하지 않았다는 것을 잊어 버렸습니다. 이 :( –