MyTable.Rows.Count does not increase when dynamically adding rows
I have a table having two rows initially. And i have also two buttons that adds and delete rows dynamically.. When i click the "add row" button it will add rows sucessfully. My first problem is, i notice that the value of table1.rows.count does not increasing. It always remain on 2. Which i initially set on design time.
Also after solving this problem, please help me to do the things to delete the last row when i click the "delete row" .
Thanks
Mahesh ChandPosted Jul 21, 2005, 6:21 AM
nivramPosted Jul 20, 2005, 11:42 PM
" AddOTField(intCounter.ToString) Next End If End Sub Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click ViewState("RowCount") = 1 ot_form_top.Visible = True ot_form_below.Visible = False End Sub Sub AddOTField(ByVal strFieldNum As String) Dim td1 As HtmlTableCell Dim td2 As HtmlTableCell Dim td3 As HtmlTableCell Dim td4 As HtmlTableCell Dim td5 As HtmlTableCell Dim td6 As HtmlTableCell Dim td7 As HtmlTableCell Dim tr As HtmlTableRow Dim txtTextBox As TextBox Dim chkCheckBox As CheckBox Dim ltlControl As LiteralControl 'Create_dynamic_controls: ' Create a new row tr = New HtmlTableRow tr.ID = "Row" & strFieldNum ' Create Columns ' Column for Date of OT td1 = New HtmlTableCell txtTextBox = New TextBox txtTextBox.ID = "txtOTField" & strFieldNum & "1" txtTextBox.Width = 70 txtTextBox.Text = txtTextBox.ID td1.Controls.Add(txtTextBox) ' Column for OT in td2 = New HtmlTableCell txtTextBox = New TextBox txtTextBox.ID = "txtOTField" & strFieldNum & "2" txtTextBox.Width = 70 txtTextBox.Text = txtTextBox.ID td2.Controls.Add(txtTextBox) ' Column for OT out td3 = New HtmlTableCell txtTextBox = New TextBox txtTextBox.ID = "txtOTField" & strFieldNum & "3" txtTextBox.Width = 70 txtTextBox.Text = txtTextBox.ID td3.Controls.Add(txtTextBox) ' Column for Sunday Premium td4 = New HtmlTableCell chkCheckBox = New CheckBox chkCheckBox.ID = "chkOTField" & strFieldNum & "4" 'chkCheckBox.Text = chkCheckBox.ID td4.Controls.Add(chkCheckBox) ' Column for Night Diff td5 = New HtmlTableCell chkCheckBox = New CheckBox chkCheckBox.ID = "chkOTField" & strFieldNum & "5" 'chkCheckBox.Text = chkCheckBox.ID td5.Controls.Add(chkCheckBox) ' Column for Reason td6 = New HtmlTableCell txtTextBox = New TextBox txtTextBox.ID = "txtOTField" & strFieldNum & "6" txtTextBox.Text = txtTextBox.ID td6.Controls.Add(txtTextBox) ' Column for Delete Row td7 = New HtmlTableCell 'btnDelete = New Button 'btnDelete.ID = "btnDeleteRow" & strFieldNum 'btnDelete.Text = "Delete" ltlControl = New LiteralControl ltlControl.ID = "ltlControl" & strFieldNum ltlControl.Text = tr.ID td7.Controls.Add(ltlControl) tr.Cells.Add(td1) tr.Cells.Add(td2) tr.Cells.Add(td3) tr.Cells.Add(td4) tr.Cells.Add(td5) tr.Cells.Add(td6) tr.Cells.Add(td7) my_ot_table.Rows.Add(tr) End Sub
Mahesh ChandPosted Jul 20, 2005, 9:06 PM
nivramPosted Jul 20, 2005, 8:58 PM
Mahesh ChandPosted Jul 20, 2005, 11:17 AM