Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Dynamically Add Rows to html table from code behind [modified]

Dynamically Add Rows to html table from code behind [modified]

Scheduled Pinned Locked Moved C#
helphtmldatabasesysadmintutorial
8 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Ali Rashid
    wrote on last edited by
    #1

    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>

    D S OriginalGriffO P 4 Replies Last reply
    0
    • A Ali Rashid

      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>

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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...

      A 1 Reply Last reply
      0
      • A Ali Rashid

        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>

        S Offline
        S Offline
        Saksida Bojan
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • D Dave Kreskowiak

          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...

          A Offline
          A Offline
          Ali Rashid
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • A Ali Rashid

            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>

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #5

            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

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            S 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              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

              S Offline
              S Offline
              Saksida Bojan
              wrote on last edited by
              #6

              This page cam be easly costumized with HTML tags. tag like </td> can realy break forum

              1 Reply Last reply
              0
              • A Ali Rashid

                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>

                P Offline
                P Offline
                PunkIsNotDead
                wrote on last edited by
                #7

                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

                A 1 Reply Last reply
                0
                • P PunkIsNotDead

                  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

                  A Offline
                  A Offline
                  Ali Rashid
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups