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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:46:27+00:00 2026-05-15T20:46:27+00:00

I want to build a form where users can enter some data in a

  • 0

I want to build a form where users can enter some data in a few text boxes and click the “Add” button and have the the data appear in a grid or something like it. They need to be able to enter multiple rows.

Then when they are done they can click the “Save” button to save the data to the database.

How do I get the data from from the text boxes into the “grid”?

EDIT

Here’s what I have so far

   protected void Page_Load(object sender, EventArgs e)

{

    DataTable myDataTable = new DataTable();

    DataColumn dc1 = new DataColumn("Employee");
    myDataTable.Columns.Add(dc1);
    DataColumn dc2 = new DataColumn("Category");
    myDataTable.Columns.Add(dc2);
    DataColumn dc3 = new DataColumn("Description");
    myDataTable.Columns.Add(dc3);
    DataColumn dc4 = new DataColumn("P/S/N");
    myDataTable.Columns.Add(dc4);
    DataColumn dc5 = new DataColumn("Hours");
    myDataTable.Columns.Add(dc5);
    DataColumn dc6 = new DataColumn("WeekEnding");
    myDataTable.Columns.Add(dc6);

}
protected void btnAddToGrid_Click(object sender, EventArgs e)

{
    DataRow row = myDataTable.NewRow();// i'm getting error here sayind myDataTable does not exist

    row["Employee"] = LoginName1.ToString();
    row["Category"] = ddlCategory.SelectedValue;
    row["Description"] = txtDescription.Text;
    row["P/S/N"] = ddlPSN.SelectedValue;
    row["Hours"] = ddlHours.SelectedValue;
    row["WeekEnding"] = txtWeekEnding.Text;

    myDataTable.Rows.Add(row);
  • 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-15T20:46:27+00:00Added an answer on May 15, 2026 at 8:46 pm

    Ok your first problem from your comment:

    i'm getting error here sayind myDataTable does not exist
    

    Is because you defined your table in the Page_Load and then it goes out of scope at the end of the function. It sounds like you don’t understand the basic concepts of ASP.NET and what you are trying to do.

    Here is a quick and dirty untested solution to your problem but I must stress that you should try and understand why this solution works before trying to extend it or do more in ASP.NET. I hope my 10 minutes of my time helps you get a good start into understanding C# and ASP.NET.

    [Serializable]
    public class YourData
    {
        public string Employee { get; set; }
        public string Category { get; set; }
        public string Description { get; set; }
        public string P_S_N { get; set; }
        public string Hours { get; set; }
        public string WeekEnding { get; set; }
    }
    
    // Used to add your list of data to the viewstate cache
    // (There are other ways to store data between posts but I am trying to keep it simple)
    public void SetYourCachedData(List<YourData> data)
    {
        ViewState["YourDataCache"] = data;
    }
    
    // Used to get your save data so far
    public List<YourData> GetYourCachedData()
    {
        return ViewState["YourDataCache"] == null ?
            new List<YourData>() : (List<YourData>)(ViewState["YourDataCache"]);
    }
    
    protected void Page_Load(object sender, EventArgs e)
    {
        // Do nothing
    }
    
    protected void btnAddToGrid_Click(object sender, EventArgs e)
    {
        // Get the data and store it in the ViewState to cache it between post backs
        // Assuming one record added with each click.
        List<YourData> data = GetYourCachedData();
        data.Add(new YourData()
        {
            Employee = LoginName1.ToString(),
            Category = ddlCategory.SelectedValue,
            Description = txtDescription.Text,
            P_S_N = ddlPSN.SelectedValue,
            Hours = ddlHours.SelectedValue,
            WeekEnding = txtWeekEnding.Text
        });            
    
        // You can bind to any type of collection easily.
        // You don't need to use a DataTable with a GridView
        yourGrid.DataSource = data;
        yourGrid.DataBind();
    
        SetYourCachedData(data);
    }
    
    protected void btnSaveData_Click(object sender, EventArgs e)
    {
        // Pull data from the ViewState cache
        List<YourData> data = GetYourCachedData();
    
        // Now iterate through data to save it to your database...
        // look this up if you don't know how as this is a lot more work.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to build a page which contains some text boxes and a grid
I have to build a large form for users to fill out in order
I build a form with entity type like this: $form = $this->createFormBuilder() ->add('users', 'entity',
I'm a newcomer to Rails. I want to build a simple form that determines
I want to build a system where an admin can create forms with the
I want to build a back end of a general web form which contains
I have a textbox on a MS Access form that users are going to
We're planning to create a web application where users can build custom forms, choosing
I want to open a WPF4/EF4 form in AddNew mode so the user can
I want to build an string/text manipulation app that: An app consists of a

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.