Click here to Skip to main content
16,020,103 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to insert the multiple txtbox values to a table single time. When I will store the values to all textboxes that will store in table. Here textboxes are automatic created

Lookout my code:
protected void cmdCreate0_Click(object sender, EventArgs e)
   {

       table1.Controls.Clear();
       int rows = Int32.Parse(txtRows.Text);
       int cols = Int32.Parse(txtCols.Text);
       for (int row = 0; row < rows; row++)
       {

           TableRow rowNew = new TableRow();

           table1.Controls.Add(rowNew);
           for (int col = 0; col < cols; col++)
           {

               TableCell cellNew = new TableCell();
               TextBox txtContent = new TextBox();

               cellNew.Controls.Add(txtContent);

               if (chkBorder.Checked)
               {
                   cellNew.BorderStyle = BorderStyle.Inset;
                   cellNew.BorderWidth = Unit.Pixel(1);
               }

               rowNew.Controls.Add(cellNew);
           }
       }
   }
Posted
Updated 23-Dec-10 1:28am
v2

1 solution

can u explain more what u want to do?
 
Share this answer
 
Comments
sat_100m 23-Dec-10 8:52am    
I have created 2 textbox txtRows and txtCols........when i input some value on dem it has created
the same no. of row and columns with every cell containing blank textboxes....i want to insert valus on dat textboxes to a table in database(sql)....

<div>
Rows:
<asp:TextBox ID="txtRows" runat="server" />
 Cols:
<asp:TextBox ID="txtCols" runat="server" />
<br /><br />
<asp:CheckBox ID="chkBorder" runat="server"
Text="Put Border Around Cells" />
<br /><br />

<asp:Button ID="cmdCreate0" runat="server"
Text="Create Table with textbox" onclick="cmdCreate0_Click" />
<br /><br />
<asp:Table ID="table1" runat="server" />
<br />
<br />
 <br />
<br />
 <br />
</div>



public partial class table : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Configure the table's appearance.
// This could also be performed in the .aspx file
// or in the cmdCreate_Click event handler.
table1.BorderStyle = BorderStyle.Inset;
table1.BorderWidth = Unit.Pixel(1);

}



protected void cmdCreate0_Click(object sender, EventArgs e)
{

table1.Controls.Clear();
int rows = Int32.Parse(txtRows.Text);
int cols = Int32.Parse(txtCols.Text);
for (int row = 0; row < rows; row++)
{

TableRow rowNew = new TableRow();

table1.Controls.Add(rowNew);
for (int col = 0; col < cols; col++)
{

TableCell cellNew = new TableCell();
TextBox txtContent = new TextBox();

cellNew.Controls.Add(txtContent);

if (chkBorder.Checked)
{
cellNew.BorderStyle = BorderStyle.Inset;
cellNew.BorderWidth = Unit.Pixel(1);
}

rowNew.Controls.Add(cellNew);
}
}
}


}

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