By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,344 Members | 1,139 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,344 IT Pros & Developers. It's quick & easy.

table generation and dynamic row creation

P: 1
I have been working on a webform where I need to generatet a dynamic html table. Then with each button click I need to add a row with cells to the table. My problem is when I click my add row button it mearly wirtes over the existing row.

Here is the code I have so far.

Expand|Select|Wrap|Line Numbers
  1. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2. Dim tblName As New HtmlTable
  3. 'following lines set date fields to now by default 
  4. Dim myDate As Date = Now
  5. txtDate.Text = Format(myDate, "MM/dd/yyyy")
  6. txtLdod.Text = Format(myDate, "MM/dd/yyyy")
  7. txtEmpSigDate.Text = Format(myDate, "MM/dd/yyyy")
  8. txtHrmDate.Text = Format(myDate, "MM/dd/yyyy")
  9.  
  10.  
  11. 'Dim dynamicMaskedTextBox As New MaskedTextBox()
  12. 'Dim dtDate As Date
  13. 'txtDate.Text = Format(Date, "mm-dd-yyyy")
  14. ' txtLdod.Text = Format("mm-dd-yyy")
  15. ' txtEmpSigDate.Text = Format("mm-dd-yyy")
  16. ' txtHrmDate.Text = Format("mm-dd-yyy")
  17. ' Format(txtDate.Text, vbShortDate)
  18. End Sub
  19.  
  20. Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAdd.Click
  21.  
  22. Dim tblTr As New HtmlTableRow()
  23. Dim strNumberOfUnits, strItem, strSerial As New HtmlTableCell()
  24. Dim tb As New TextBox
  25. Dim tblRows As Integer
  26. Dim tblCloumns As Integer
  27.  
  28.  
  29. 'add new row
  30. tblName.Rows.Add(tblTr)
  31.  
  32. 'Sets the number of items
  33. tblTr.Cells.Add(strNumberOfUnits)
  34. strNumberOfUnits.InnerText = "1"
  35. strNumberOfUnits.ID = "strNumberOfUnits" & tblName.Rows.Count - 1
  36.  
  37. 'set item descriptor
  38. tblTr.Cells.Add(strItem)
  39. strItem.InnerText = ddlProperty.SelectedValue.ToString
  40. strItem.ID = "strItem" & tblName.Rows.Count - 1
  41.  
  42. 'set serial value
  43. tblTr.Cells.Add(strSerial)
  44. strSerial.Controls.Add(tb)
  45. tb.ID = "txt" & ddlProperty.SelectedValue.ToString & tblName.Rows.Count - 1
  46.  
  47. 'sets serial field 
  48. 'Dim tx As New TextBox
  49. 'tblTr.Controls.Add(tx)
  50. 'tx.ID = "Row_" & tblName.Rows.Count - 1
  51. ''strSerial.InnerText = InputBox("Input corresponding item/Serial number", "Items Number")
  52. ''tblTr.Cells.Add(strSerial)
  53.  
  54.  
  55. End Sub
Thank you for your help.
Apr 1 '13 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.