Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to genarate a row of text boxes dynamically? Can I use an AJAX or any other toolkit's control??
For eg: After clicking "add another" button, a row of 6 text boxes should be generated.
Please help me.
Posted
Updated 29-Apr-12 21:14pm
v4
Comments
[no name] 24-Apr-12 8:43am    
Your question is not proper.. are you looking for gridview row? Or can you provide a small description of your question?
Sandeep Mewara 24-Apr-12 10:16am    
This is not a well framed question! We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific.
Use the "Improve question" link to edit your question and provide better information.
Joshi, Rushikesh 24-Apr-12 11:48am    
How many text box should a row contain, please change your question and provide more details.
Mohamed Mitwalli 24-Apr-12 13:56pm    
take look on the solution is this what you mean ??

Hi ,
Try this
C#
int countTimes = 0;
 protected void Button2_Click(object sender, EventArgs e)
 {
     if (ViewState["countTimes"] == null)
     {
         countTimes = 1;
     }
     else
     {
         countTimes = Convert.ToInt32(ViewState["countTimes"]);
     }
     for (int i = 0; i < countTimes; i++)
     {
         TableRow row = new TableRow();
         TableCell cell = new TableCell();
         TextBox txt = new TextBox();
         txt.ID = "txt"+i;
         TextBox txt1 = new TextBox();
         txt1.ID = "txt" + i;
         TextBox txt2 = new TextBox();
         txt2.ID = "txt" + i;
         TextBox txt3= new TextBox();
         txt3.ID = "txt" + i;
         TextBox txt4 = new TextBox();
         txt4.ID = "txt" + i;
         TextBox txt5 = new TextBox();
         txt5.ID = "txt" + i;

         TextBox txt6 = new TextBox();
         txt6.ID = "txt" + i;
         cell.Controls.Add(txt);
         cell.Controls.Add(txt1);
         cell.Controls.Add(txt2);
         cell.Controls.Add(txt3);
         cell.Controls.Add(txt4);
         cell.Controls.Add(txt5);
         cell.Controls.Add(txt6);

         row.Controls.Add(cell);
         Table1.Controls.Add(row);
     }
     countTimes = countTimes + 1;
     ViewState.Add("countTimes", countTimes);
 }


ASP.NET
<div>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    <br />
    <asp:Table ID="Table1" runat="server">
    </asp:Table>
</div>



Best Regards
M.Mitwalli
 
Share this answer
 
v4
Comments
Sandeep Mewara 24-Apr-12 10:16am    
OP is talking of some 'row' to get added. Above solution does not do anything like that.
Mohamed Mitwalli 24-Apr-12 13:46pm    
I update the solution take look on it .
Sandeep Mewara 24-Apr-12 14:01pm    
Looks ok now. :thumbsup:
Mohamed Mitwalli 24-Apr-12 14:20pm    
Thanks Sandeep :)
maajanes 25-Apr-12 3:45am    
Thank You very much Mr.Sandeep. The code is working well. But I have to generate a row of 6 text boxes. Can you give me a solution for this requirement. Sorry, that I have not mentioned it earlier.
Try this .may be help

C#
Table tb = new Table();

tb.BorderWidth = Unit.Pixel(5);

for (int i = 1; i <= Convert.ToInt32(TextBox1.Text ); i++)

{

TableRow tr = new TableRow();

for (int j = 1; j <= 3; j++)

{

TableCell td = new TableCell();

TextBox c_text = new TextBox();

c_text.Visible = true; 

c_text.Text = "R"+i.ToString()+j.ToString();

c_text.ID = "R" + i.ToString() + j.ToString();

td.Controls.Add(c_text);

tr.Cells.Add(td);

tb.Rows.Add(tr);

form1.Controls.Add(tb);

}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900