Hi,
I have a button which when pressed adds a new row to a table using updatepanel (without page reload). It adds the first row fine, however it never adds anymore rows after that and it seems that it always ever thinks that there is one row. I thought about using a viewState to record the rowCount and do table.controls.addAt(viewState("rowCount"), newRow) but this doesnt work either.
Behind VB code:
Protected Sub addResponseRow(ByVal sender As Object, ByVal e As System.EventArgs) Handles addResponses_btn.Click Dim rowCount = options_tbl.Rows.Count Dim newRow = New TableRow debug_tb.Text = rowCount 'This is always ever showing as 1 and not the correct row numbers' Dim newCell_checkbox = New TableCell newCell_checkbox.CssClass = "optionRemover" Dim newCheckbox = New CheckBox newCheckbox.CssClass = "chk" newCell_checkbox.Controls.Add(newCheckbox) newRow.Controls.Add(newCell_checkbox) Dim newCell_label = New TableCell newCell_label.CssClass = "optionNumber" Dim newLabel = New Label newLabel.Text = rowCount + 1 newCell_label.Controls.Add(newLabel) newRow.Controls.Add(newCell_label) Dim newCell_textbox = New TableCell newCell_textbox.CssClass = "optionValues" Dim newTextbox = New TextBox newTextbox.MaxLength = 100 newTextbox.Width = "350" newCell_textbox.Controls.Add(newTextbox) newRow.Controls.Add(newCell_textbox) Dim newCell_radio = New TableCell newCell_radio.CssClass = "optionExclusive" Dim newRadio = New RadioButton newRadio.GroupName = "optionGroup" newRadio.ID = "radio_Option_" & rowCount newCell_radio.Controls.Add(newRadio) newRow.Controls.Add(newCell_radio) options_tbl.Controls.AddAt(rowCount, newRow) End Sub
<asp:ScriptManager ID="ScriptManager1" runat="server" ></asp:ScriptManager><asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate><asp:button ID="addResponses_btn" runat="server" text="Add Row" style="margin-left:30px;" CausesValidation="false"/> <asp:table runat="server" cellpadding="0" cellspacing="0" id="options_tbl" style="border:1px solid #ccc; font-size:inherit;"><asp:TableRow> <asp:TableCell CssClass="optionRemover"><asp:CheckBox runat="server" CssClass="chk"/> </asp:TableCell><asp:TableCell CssClass="optionNumber"><asp:label runat="server">1</asp:label></asp:TableCell><asp:TableCell CssClass="optionValues"><asp:TextBox onBlur="checkRangeChange()" MaxLength="100" runat="server" Width="350px"></asp:TextBox></asp:TableCell><asp:TableCell CssClass="optionExclusive"><asp:RadioButton GroupName="optionGroup" id="radio_Option" runat="server"/></asp:TableCell></asp:TableRow></asp:table></ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="addResponses_btn" EventName="click" /></Triggers></asp:UpdatePanel>
Any ideas?
Thank you :)