Hi,
My requriment is i want to give dinamicaly adding controls in my web page . that means if i click add button dinamicallly add textboxs in my page. like wise how many times if i click add buton such textboxs will apper. how to do.
Thanks in Advance
Loading
suchi ranaPosted Dec 30, 2011, 7:00 AM
Hemant KumarPosted Dec 30, 2011, 4:33 AM
http://geekswithblogs.net/dotNETvinz/archive/2009/03/17/dynamically-adding-textbox-control-to-aspnet-table.aspx
http://forums.asp.net/t/1152363.aspx
Satyapriya NayakPosted Dec 30, 2011, 4:32 AM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
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