• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 539
  • 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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
pauledwardianAuthor Commented:
0
 
Obadiah ChristopherCommented:
<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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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