Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8881099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:16:41+00:00 2026-06-14T20:16:41+00:00

I want to add row to table by user click, not when do that

  • 0

I want to add row to table by user click, not when do that in code behind of asp
and then when click on “addRowButton”, only one row can be add to table. So, I search this problem in Google, and see some articles about “ViewState” in asp that causing this problem, but couldn’t understand that how can I use or change the “ViewState” to solve this problem.

Here is template of my Table in ASP Page:

<table runat="server" ID="myTable">
<tr><td>
<asp:textbox runat="server" ID="txt1"></asp:textbox>
</td></tr>
</table>

and i’m using this code to add some row with specific cells to Table:

protected void AddNewRow(object sender, EventArgs e)
    { 
        HtmlTable tbl = (System.Web.UI.HtmlControls.HtmlTable)this.FindControl("myTable");
        HtmlTableCell cell = new HtmlTableCell();
        HtmlTableRow row = new HtmlTableRow();
        TextBox txt = new TextBox();
        txt.ID = "txtTest";
        cell.Controls.Add(txt);
        row.Controls.Add(cell);
        int rowNumber = tbl.Rows.Count;
        tbl.Controls.AddAt(rowNumber, row);
    }

Please help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:16:42+00:00Added an answer on June 14, 2026 at 8:16 pm

    You need to store the current number of rows into the ViewState field (use the ViewState property of the current Page context). Or store the same information in a hidden field, then call AddNewRow as many times as ViewState says so during the OnInit event of your page.

    Here’s some psuedocode:

    During OnInit:
        Is this a postback? If so...
            Read the number of table-rows N from ViewState["RowCount"]
            For(I=0 to N) AddTableRow()
    
    During AddRow_ClickHandler
        AddTableRow()
        ViewState["RowCount"]++
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add linearlayout in table row and that linear layout will hold
I have this JSF table. I want to add row numbers. <?xml version=1.0 encoding=UTF-8?>
I want to add a new row to my JSON when the user clicks
Please see the below code: I am have a table row defined using asp.net
I want to add row with remove button through javascript in html div formate.
I want add label to every row in tableview at right side of the
I want to add a button to each row of a column of an
I want to add explicit lock on row which is currently being updated and
Does the row below is required in AssemblyInfo.cs if i want to add an
I want to insert row for each day to add new values, and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.