0
Hi , Thanks for your response
0
Hi please refer this link
http://geekswithblogs.net/dotNETvinz/archive/2009/03/17/dynamically-adding-textbox-control-to-aspnet-table.aspx
http://forums.asp.net/t/1152363.aspx
0
Hi Suchi,
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:textbox runat="Server" id="txtTBCount" Columns="3" />
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtTBCount"
MinimumValue="1" MaximumValue="10" Type="Integer"
ErrorMessage="Choose a value between 1 and 10" />
<br />
<asp:button ID="Button1" runat="server" Text="Create Dynamic TextBoxes"
OnClick="CreateTextBoxes" />
<p>
<asp:PlaceHolder runat="server" id="TextBoxesHere" />
</p>
</div>
</form>
</body>
</html>
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void CreateTextBoxes(object sender, EventArgs e)
{
CreateTextBoxes();
}
int count = 1;
void IterateThroughChildren(Control parent)
{
foreach (Control c in parent.Controls)
{
if (c.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox"))
{
((TextBox) c).Text = "TextBox " + count.ToString();
((TextBox) c).Columns = 10;
count++;
}
if (c.Controls.Count > 0)
{
IterateThroughChildren(c);
}
}
}
void CreateTextBoxes()
{
if (!Page.IsValid) return;
int n = Int32.Parse(txtTBCount.Text);
// now, create n TextBoxes, adding them to the PlaceHolder TextBoxesHere
for (int i = 0; i < n; i++)
{
TextBoxesHere.Controls.Add(new TextBox());
}
// now, set the Text property of each TextBox
IterateThroughChildren(this);
}
}
Thanks
![](/images/loader.svg)