Reputation: 19
How to create dynamic textbox using asp.net and C# .how to store in database .please any one help me i am new to this .Thanks in advance
Upvotes: 1
Views: 6206
Reputation: 3531
I hope this can help you: For Data access you can take a look here: 1. http://www.asp.net/web-forms 2. Download "Professional Asp.Net 4 (wrox)" or "Microsoft ASP.NET 4 Step by Step"
And the code for add textbox(in this case)dinamically in a gridview is like this
void addTextBoxInGridView()
{
int nr = 0, nc = 0;
nr = this.GridView1.Rows.Count;
if (nr > 0)
{
nc = this.GridView1.HeaderRow.Cells.Count;
int r = 0, c = 0;
for (r = 0; r < nr; r++)
{
for (c = 0; c < nc; c++)
{
string v1 = "";
v1 = HttpUtility.HtmlDecode(this.GridView1.Rows[r].Cells[c].Text.ToString());
TextBox textbox = new TextBox();
textbox.Text = v1;
textbox.EnableViewState = true;
textbox.Style["text-align"] = "center";
textbox.Width = 40;
textbox.ID = "txt" + Convert.ToString(r) + Convert.ToString(c);
this.GridView1.Rows[r].Cells[c].Controls.Add(textbox);
}
}
}
}
Happy code!!
Upvotes: 1
Reputation: 44906
Here is some research for you that should get you headed in the right direction.
Adding Controls to page dynamically
Upvotes: 0