• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 536
  • Last Modified:

C# Placeholder Generate 4 textboxes in a row

How can I add a placeholder inside a table?

<asp:PlaceHolder ID="Table1" runat="server"></asp:PlaceHolder>

Open in new window

0
pauledwardian
Asked:
pauledwardian
  • 4
  • 3
1 Solution
 
YZlatCommented:
try

TextBox tb;
Panel pnl;

for(int i=1; i<=4; i++)
{
      tb=new TextBox();
      tb.id="TextBox" + i;
      pnl=Page.FindControl("Table1");
      pnl.Controls.Add(tb);
}
0
 
YZlatCommented:
as I understood you have a panel on your page with id Table1 and you want to add controls inside that panel?
0
 
YZlatCommented:
TextBox tb;
        Panel pnl;

        for (int i = 1; i <= 4; i++)
        {
            tb = new TextBox();
            tb.ID = "TextBox" + i;
            pnl = (Panel) this.FindControl("Table1");
            pnl.Controls.Add(tb);
        } 

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
pauledwardianAuthor Commented:
0
 
informaniacCommented:
<div>
<asp:GridView ID="gvTextBox" runat="server" AutoGenerateColumns="false" ShowHeader="false">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:TextBox ID="txt1" runat="server" Width="100px"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:TextBox ID="txt2" runat="server" Width="100px"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:TextBox ID="txt3" runat="server" Width="100px"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:TextBox ID="txt4" runat="server" Width="100px" TextMode="MultiLine"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
</div>
<div>
<asp:Button ID="btnAddRows" runat="server" Text="Add Rows" 
            onclick="btnAddRows_Click" />
</div>

Open in new window

        protected void btnAddRows_Click(object sender, EventArgs e)
        {
DataTable dtText;
            if (Session["dt"] == null)
                dtText = new DataTable();
            else
                dtText = (DataTable)Session["dt"];

            DataRow dr;

            dr = dtText.NewRow();
            dtText.Rows.Add(dr);

            gvTextBox.DataSource = dtText;
            gvTextBox.DataBind();
        }

Open in new window

0
 
pauledwardianAuthor Commented:
Your code looks greate, however it does not add a new row after clicking on the "Add Rows" button again.
It only adds the row once!
0
 
YZlatCommented:
did you try my code?
0
 
pauledwardianAuthor Commented:
Thanks!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now