Dynamically Add Rows to html table from code behind [modified]
-
Hi Guys! I am in a bit of a Dilemma here and need some help. I have a table that has a row and three columns which are showed to the user after the page loads. There is a button which calls a code behind function to add a new row. The first time the user clicks, the row is added properly, no problem. The second time however, the row is not added but the previous row that was added is updated with the new id/name etc. Also the second time, the drop down menu gives an error which is quiet ridiculous, something to do with accessing innerHtml of the drop down menu when I am not even asking the compiler to assign anything of that sort. Please have a look and let me know where the problem is which my brain cells are failing to recognise. Note: I have tried all the different methods to add the row for example table.Rows.Insert(index,htmlRow) etc. Thanks is Advance. Below id my code for reference: ============================= Front End [HTML - Table only] ============================= <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <table cellpadding="3" cellspacing="3" runat="server"> <tr> <td style="font-family:Courier New; font-size:12pt;"><b>Loan Type</b></td> <td style="font-family:Courier New; font-size:12pt;"><b>Amount Owing</b></td> <td style="font-family:Courier New; font-size:12pt;"><b>Monthly Repayments</b></td> </tr> </table> <table cellpadding="3" cellspacing="3" id="tblLoanTypes" runat="server"> <tr> <td width="33%"> <select name="loanType1" id="loanType1" class="txtNormalDrp" runat="server"> <option value="" selected="selected">Please Select</option> <option value="Home Loan">Home Loan</option> <option value="Investment Loan">Investment Loan</option> <option value="Credit Card">Credit Card</option> <option value="Personal Loan">Personal Loan</option> <option value="Store Cards">Store Cards</option> <option value="Tax Debt">Tax Debt</option> <option value="Other">Other</option> </select> </td> <td width="33%"><input type="text" class="txtBalrepayments" name="balance1" id="balance1" onfocusout="fcnAddTotals();" onkeypress="return numbersonly(event, false)" /></td>
-
Hi Guys! I am in a bit of a Dilemma here and need some help. I have a table that has a row and three columns which are showed to the user after the page loads. There is a button which calls a code behind function to add a new row. The first time the user clicks, the row is added properly, no problem. The second time however, the row is not added but the previous row that was added is updated with the new id/name etc. Also the second time, the drop down menu gives an error which is quiet ridiculous, something to do with accessing innerHtml of the drop down menu when I am not even asking the compiler to assign anything of that sort. Please have a look and let me know where the problem is which my brain cells are failing to recognise. Note: I have tried all the different methods to add the row for example table.Rows.Insert(index,htmlRow) etc. Thanks is Advance. Below id my code for reference: ============================= Front End [HTML - Table only] ============================= <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <table cellpadding="3" cellspacing="3" runat="server"> <tr> <td style="font-family:Courier New; font-size:12pt;"><b>Loan Type</b></td> <td style="font-family:Courier New; font-size:12pt;"><b>Amount Owing</b></td> <td style="font-family:Courier New; font-size:12pt;"><b>Monthly Repayments</b></td> </tr> </table> <table cellpadding="3" cellspacing="3" id="tblLoanTypes" runat="server"> <tr> <td width="33%"> <select name="loanType1" id="loanType1" class="txtNormalDrp" runat="server"> <option value="" selected="selected">Please Select</option> <option value="Home Loan">Home Loan</option> <option value="Investment Loan">Investment Loan</option> <option value="Credit Card">Credit Card</option> <option value="Personal Loan">Personal Loan</option> <option value="Store Cards">Store Cards</option> <option value="Tax Debt">Tax Debt</option> <option value="Other">Other</option> </select> </td> <td width="33%"><input type="text" class="txtBalrepayments" name="balance1" id="balance1" onfocusout="fcnAddTotals();" onkeypress="return numbersonly(event, false)" /></td>
Go back and edit your post. There's some tag in it that's screwing up the formatting of the entire forum!
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
Hi Guys! I am in a bit of a Dilemma here and need some help. I have a table that has a row and three columns which are showed to the user after the page loads. There is a button which calls a code behind function to add a new row. The first time the user clicks, the row is added properly, no problem. The second time however, the row is not added but the previous row that was added is updated with the new id/name etc. Also the second time, the drop down menu gives an error which is quiet ridiculous, something to do with accessing innerHtml of the drop down menu when I am not even asking the compiler to assign anything of that sort. Please have a look and let me know where the problem is which my brain cells are failing to recognise. Note: I have tried all the different methods to add the row for example table.Rows.Insert(index,htmlRow) etc. Thanks is Advance. Below id my code for reference: ============================= Front End [HTML - Table only] ============================= <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <table cellpadding="3" cellspacing="3" runat="server"> <tr> <td style="font-family:Courier New; font-size:12pt;"><b>Loan Type</b></td> <td style="font-family:Courier New; font-size:12pt;"><b>Amount Owing</b></td> <td style="font-family:Courier New; font-size:12pt;"><b>Monthly Repayments</b></td> </tr> </table> <table cellpadding="3" cellspacing="3" id="tblLoanTypes" runat="server"> <tr> <td width="33%"> <select name="loanType1" id="loanType1" class="txtNormalDrp" runat="server"> <option value="" selected="selected">Please Select</option> <option value="Home Loan">Home Loan</option> <option value="Investment Loan">Investment Loan</option> <option value="Credit Card">Credit Card</option> <option value="Personal Loan">Personal Loan</option> <option value="Store Cards">Store Cards</option> <option value="Tax Debt">Tax Debt</option> <option value="Other">Other</option> </select> </td> <td width="33%"><input type="text" class="txtBalrepayments" name="balance1" id="balance1" onfocusout="fcnAddTotals();" onkeypress="return numbersonly(event, false)" /></td>
You have broken Forum, if you can edid, edid part that uses <>. I recomend when you pasting use option: "Encode "<" (and other HTML) characters when pasting". For the actual code, please use PRE tags, so that is more readable
-
Go back and edit your post. There's some tag in it that's screwing up the formatting of the entire forum!
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...Hi Dave! Please let me know if this edit solved the problem, else I can delete the post. Sorry for any inconvenience caused Regards, Ali
-
Hi Guys! I am in a bit of a Dilemma here and need some help. I have a table that has a row and three columns which are showed to the user after the page loads. There is a button which calls a code behind function to add a new row. The first time the user clicks, the row is added properly, no problem. The second time however, the row is not added but the previous row that was added is updated with the new id/name etc. Also the second time, the drop down menu gives an error which is quiet ridiculous, something to do with accessing innerHtml of the drop down menu when I am not even asking the compiler to assign anything of that sort. Please have a look and let me know where the problem is which my brain cells are failing to recognise. Note: I have tried all the different methods to add the row for example table.Rows.Insert(index,htmlRow) etc. Thanks is Advance. Below id my code for reference: ============================= Front End [HTML - Table only] ============================= <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <table cellpadding="3" cellspacing="3" runat="server"> <tr> <td style="font-family:Courier New; font-size:12pt;"><b>Loan Type</b></td> <td style="font-family:Courier New; font-size:12pt;"><b>Amount Owing</b></td> <td style="font-family:Courier New; font-size:12pt;"><b>Monthly Repayments</b></td> </tr> </table> <table cellpadding="3" cellspacing="3" id="tblLoanTypes" runat="server"> <tr> <td width="33%"> <select name="loanType1" id="loanType1" class="txtNormalDrp" runat="server"> <option value="" selected="selected">Please Select</option> <option value="Home Loan">Home Loan</option> <option value="Investment Loan">Investment Loan</option> <option value="Credit Card">Credit Card</option> <option value="Personal Loan">Personal Loan</option> <option value="Store Cards">Store Cards</option> <option value="Tax Debt">Tax Debt</option> <option value="Other">Other</option> </select> </td> <td width="33%"><input type="text" class="txtBalrepayments" name="balance1" id="balance1" onfocusout="fcnAddTotals();" onkeypress="return numbersonly(event, false)" /></td>
Please contact the hamsters (via the site bugs and suggestions forum) to let them know what you did to break the forum: I am sure they will want to make sure it can't happen again!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
-
Please contact the hamsters (via the site bugs and suggestions forum) to let them know what you did to break the forum: I am sure they will want to make sure it can't happen again!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
This page cam be easly costumized with HTML tags. tag like </td> can realy break forum
-
Hi Guys! I am in a bit of a Dilemma here and need some help. I have a table that has a row and three columns which are showed to the user after the page loads. There is a button which calls a code behind function to add a new row. The first time the user clicks, the row is added properly, no problem. The second time however, the row is not added but the previous row that was added is updated with the new id/name etc. Also the second time, the drop down menu gives an error which is quiet ridiculous, something to do with accessing innerHtml of the drop down menu when I am not even asking the compiler to assign anything of that sort. Please have a look and let me know where the problem is which my brain cells are failing to recognise. Note: I have tried all the different methods to add the row for example table.Rows.Insert(index,htmlRow) etc. Thanks is Advance. Below id my code for reference: ============================= Front End [HTML - Table only] ============================= <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <table cellpadding="3" cellspacing="3" runat="server"> <tr> <td style="font-family:Courier New; font-size:12pt;"><b>Loan Type</b></td> <td style="font-family:Courier New; font-size:12pt;"><b>Amount Owing</b></td> <td style="font-family:Courier New; font-size:12pt;"><b>Monthly Repayments</b></td> </tr> </table> <table cellpadding="3" cellspacing="3" id="tblLoanTypes" runat="server"> <tr> <td width="33%"> <select name="loanType1" id="loanType1" class="txtNormalDrp" runat="server"> <option value="" selected="selected">Please Select</option> <option value="Home Loan">Home Loan</option> <option value="Investment Loan">Investment Loan</option> <option value="Credit Card">Credit Card</option> <option value="Personal Loan">Personal Loan</option> <option value="Store Cards">Store Cards</option> <option value="Tax Debt">Tax Debt</option> <option value="Other">Other</option> </select> </td> <td width="33%"><input type="text" class="txtBalrepayments" name="balance1" id="balance1" onfocusout="fcnAddTotals();" onkeypress="return numbersonly(event, false)" /></td>
Should it be the PostBack of iBtnAddRow that generates all the code again! Try saving the table in a Session or a ViewState! :) and after every postback return it back! like
//Saving
protected void iBtnAddRow_Click(object sender, ImageClickEventArgs e)
{
//...your code
Session["YourTable"] = tblLoanTypes;
}//and returning it :)
private void Page_Load(//bla bla
{
tbl_LoanTypes = (HtmlTable)Session["YourTable"];
};P
-
Should it be the PostBack of iBtnAddRow that generates all the code again! Try saving the table in a Session or a ViewState! :) and after every postback return it back! like
//Saving
protected void iBtnAddRow_Click(object sender, ImageClickEventArgs e)
{
//...your code
Session["YourTable"] = tblLoanTypes;
}//and returning it :)
private void Page_Load(//bla bla
{
tbl_LoanTypes = (HtmlTable)Session["YourTable"];
};P
Thanks for the reply mate! I'll give it a try and see how it goes though I am sure that it might not be a good idea saving the table in the session as this is a high traffic site and people can have more than 10 rows in their table. So the table times the number of users may make the site perform slow. Nonetheless, I will carry out an SVT and see how it goes. Regards.