JordanBlackler
asked on
Help with Dynamically creating controls
This is for the web using C#.
What i'm trying to do:
I would like everytime the user clicks a button a table with 3 rows and 2 columns are created. And 3 labels and 3 textboxes are created inside the table. The user can click on the button once, enter the info, then save the document. Reopen the document later and click the button again to add even more information. So if the user does this 4 times, there will be four tables with all of the information they entered.
I'm able to do this only once. When the i click the button it creates everything, but when i click it again it wipes it away and creates the same table over it..
I'll be working on this in the meantime, but any help with be greatly apprecaited.
I used the table control in the toolbox.
I tried:
Table tblInvoice = new Table() ;
but i get an error: "_Default.Table' does not contain a definition for 'Rows' ".
I'd like to create the table dynamically rather then dropping the control on the aspx page
here is my code.
// -----INVOICE-----
TableRow tRow = new TableRow();
tblInvoice.Rows.Add(tRow);
TableCell tCell = new TableCell();
tRow.Cells.Add(tCell);
// add cell One content
Label lblInvoice = new Label();
lblInvoice.ID = "lblInvoice";
lblInvoice.Text = "Invoice #:";
tCell.Controls.Add(lblInvo ice);
// add the cell to the Cells collection
tRow.Cells.Add(tCell);
// add cell Two
TableCell tCell2 = new TableCell();
tRow.Cells.Add(tCell2);
// add cell Two content
TextBox txtInvoice = new TextBox();
txtInvoice.ID = "txtInvoice:";
txtInvoice.Text = "";
txtInvoice.Height = 18;
tCell2.Controls.Add(txtInv oice);
// add the cell to the Cells collection
tRow.Cells.Add(tCell2);
// -----AMOUNT-----
// add row Two
TableRow tRow2 = new TableRow();
tblInvoice.Rows.Add(tRow2) ;
// add cell Three
TableCell tCell3 = new TableCell();
tRow2.Cells.Add(tCell3);
// add cell Three content
Label lblAmount = new Label();
lblAmount.ID = "lblAmount";
lblAmount.Text = "Amount:";
tCell3.Controls.Add(lblAmo unt);
// add the cell to the Cells collection
tRow2.Cells.Add(tCell3);
// add cell Four
TableCell tCell4 = new TableCell();
tRow2.Cells.Add(tCell4);
// add cell Four content
TextBox txtAmount = new TextBox();
txtAmount.ID = "txtAmount";
txtAmount.Text = "";
txtAmount.Height = 18;
tCell4.Controls.Add(txtAmo unt);
// add the cell to the Cells collection
tRow2.Cells.Add(tCell4);
// -----DATE-----
// add row Three
TableRow tRow3 = new TableRow();
tblInvoice.Rows.Add(tRow3) ;
// add cell Five
TableCell tCell5 = new TableCell();
tRow3.Cells.Add(tCell5);
// add cell Five content
Label lblDateRecieved = new Label();
lblDateRecieved.ID = "lblDateRecieved";
lblDateRecieved.Text = "Date:";
tCell5.Controls.Add(lblDat eRecieved) ;
// add the cell to the Cells collection
tRow3.Cells.Add(tCell5);
// add cell Six
TableCell tCell6 = new TableCell();
tRow3.Cells.Add(tCell6);
// add cell Six content
TextBox txtDateRecieved = new TextBox();
txtDateRecieved.ID = "txtDateRecieved";
txtDateRecieved.Text = "";
txtDateRecieved.Height = 18;
Button btnCalendar = new Button();
btnCalendar.BackColor = System.Drawing.Color.White ;
btnCalendar.CssClass = "calendarImage";
btnCalendar.Width = 27;
tCell6.Controls.Add(txtDat eRecieved) ;
tCell6.Controls.Add(btnCal endar);
// add the cell to the Cells collection
tRow3.Cells.Add(tCell6);
Thanks a lot in advance.
What i'm trying to do:
I would like everytime the user clicks a button a table with 3 rows and 2 columns are created. And 3 labels and 3 textboxes are created inside the table. The user can click on the button once, enter the info, then save the document. Reopen the document later and click the button again to add even more information. So if the user does this 4 times, there will be four tables with all of the information they entered.
I'm able to do this only once. When the i click the button it creates everything, but when i click it again it wipes it away and creates the same table over it..
I'll be working on this in the meantime, but any help with be greatly apprecaited.
I used the table control in the toolbox.
I tried:
Table tblInvoice = new Table() ;
but i get an error: "_Default.Table' does not contain a definition for 'Rows' ".
I'd like to create the table dynamically rather then dropping the control on the aspx page
here is my code.
// -----INVOICE-----
TableRow tRow = new TableRow();
tblInvoice.Rows.Add(tRow);
TableCell tCell = new TableCell();
tRow.Cells.Add(tCell);
// add cell One content
Label lblInvoice = new Label();
lblInvoice.ID = "lblInvoice";
lblInvoice.Text = "Invoice #:";
tCell.Controls.Add(lblInvo
// add the cell to the Cells collection
tRow.Cells.Add(tCell);
// add cell Two
TableCell tCell2 = new TableCell();
tRow.Cells.Add(tCell2);
// add cell Two content
TextBox txtInvoice = new TextBox();
txtInvoice.ID = "txtInvoice:";
txtInvoice.Text = "";
txtInvoice.Height = 18;
tCell2.Controls.Add(txtInv
// add the cell to the Cells collection
tRow.Cells.Add(tCell2);
// -----AMOUNT-----
// add row Two
TableRow tRow2 = new TableRow();
tblInvoice.Rows.Add(tRow2)
// add cell Three
TableCell tCell3 = new TableCell();
tRow2.Cells.Add(tCell3);
// add cell Three content
Label lblAmount = new Label();
lblAmount.ID = "lblAmount";
lblAmount.Text = "Amount:";
tCell3.Controls.Add(lblAmo
// add the cell to the Cells collection
tRow2.Cells.Add(tCell3);
// add cell Four
TableCell tCell4 = new TableCell();
tRow2.Cells.Add(tCell4);
// add cell Four content
TextBox txtAmount = new TextBox();
txtAmount.ID = "txtAmount";
txtAmount.Text = "";
txtAmount.Height = 18;
tCell4.Controls.Add(txtAmo
// add the cell to the Cells collection
tRow2.Cells.Add(tCell4);
// -----DATE-----
// add row Three
TableRow tRow3 = new TableRow();
tblInvoice.Rows.Add(tRow3)
// add cell Five
TableCell tCell5 = new TableCell();
tRow3.Cells.Add(tCell5);
// add cell Five content
Label lblDateRecieved = new Label();
lblDateRecieved.ID = "lblDateRecieved";
lblDateRecieved.Text = "Date:";
tCell5.Controls.Add(lblDat
// add the cell to the Cells collection
tRow3.Cells.Add(tCell5);
// add cell Six
TableCell tCell6 = new TableCell();
tRow3.Cells.Add(tCell6);
// add cell Six content
TextBox txtDateRecieved = new TextBox();
txtDateRecieved.ID = "txtDateRecieved";
txtDateRecieved.Text = "";
txtDateRecieved.Height = 18;
Button btnCalendar = new Button();
btnCalendar.BackColor = System.Drawing.Color.White
btnCalendar.CssClass = "calendarImage";
btnCalendar.Width = 27;
tCell6.Controls.Add(txtDat
tCell6.Controls.Add(btnCal
// add the cell to the Cells collection
tRow3.Cells.Add(tCell6);
Thanks a lot in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.