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 660155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:07:29+00:00 2026-05-13T23:07:29+00:00

In my simple starter asp page I create a DataTable and populate it with

  • 0

In my simple starter asp page I create a DataTable and populate it with two rows. The web site allows users to add new rows. My problem is the DataTable doesn’t save the information. I’ve stepped through the code and the row gets added but the next time a row is added it’s not there, only the original two and the newest one to get entered.

I have gotten around this, in an inelegant way, but am really curious why the new rows are being saved.

My code:

    protected void Page_Load(object sender, EventArgs e)
    {
        _Default.NameList = new DataTable();
        DataColumn col = new DataColumn("FirstName", typeof(string));
        _Default.NameList.Columns.Add(col);
        col = new DataColumn("LastName", typeof(string));
        _Default.NameList.Columns.Add(col);
        DataRow row = _Default.NameList.NewRow();
        row["FirstName"] = "Jane";
        row["LastName"] = "Smith";
        _Default.NameList.Rows.Add(row);
        row = _Default.NameList.NewRow();
        row["FirstName"] = "John";
        row["LastName"] = "Doe";
        _Default.NameList.Rows.Add(row);
    }

    protected void AddButton_Click(object sender, EventArgs e)
    {
        DataRow row = _Default.NameList.NewRow();
        row["FirstName"] = this.TextBox1.Text;
        row["LastName"] = this.TextBox2.Text;
        _Default.NameList.Rows.Add(row);
        _Default.NameList.AcceptChanges(); // I've tried with and without this.
    }

I’ve tried saving them to GridView control but that seems like quite a bit of work.
I’m new to ASP.Net but have done windows programming in C# for the last two years.

  • 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-05-13T23:07:29+00:00Added an answer on May 13, 2026 at 11:07 pm

    You’re creating a new DataTable object each time the page loads.

    You need to persist the DataTable object to session state or a static variable, or save the data to a database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simple ASP.NET application. I have two drop-down controls. On the first-drop down I have
I am trying to get a simple demo started with ActiveMQ that will demonstrate
I'm making a simple 2 player game in XNA and started looking into saving
Sorry for the simple question but I feel like there's a smarter way to
Im sure this will be a simple one but have a project that started
Ok, simple problem hopefully. I have started to make a simple server for a
Simple as the title states: Can you use only Java commands to take a
Simple question, but one that I've been curious about...is there a functional difference between
Simple question, how do you list the primary key of a table with T-SQL?
Simple question - I've got a bucketload of cruddy html pages to clean up

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.