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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:35:34+00:00 2026-05-20T23:35:34+00:00

I have an ASP.NET DataTable which I am populating from another set of ASP:TextBox

  • 0

I have an ASP.NET DataTable which I am populating from another set of ASP:TextBox Fields to Store to then Bulk Insert into a Database when I click the add button I get System.Web.UI.WebControls.TextBox added to the DataTable Instead of the Data I have Entered in the fields can anyone tell me what I am doing wrong here.

The Code

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestDataTable._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
<form id="form1" runat="server">
  <legend>Add New Order
    <div>
    <fieldset style="height:200px;">
    <asp:Label ID="lblTips" runat="server" ForeColor="White" BackColor="Red" Width="100%" />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            Width="100%" CellPadding="4" EmptyDataText="There is no any data." 
            ForeColor="#333333" EnableModelValidation="True" GridLines="None">
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            <Columns>
                <asp:BoundField DataField="id" HeaderText="ID" Visible="False" />
                <asp:BoundField DataField="AccountRef" HeaderText="Account #" />
                <asp:BoundField DataField="InvRef" HeaderText="Invoice Ref" />
                <asp:BoundField DataField="CustOrderNo" HeaderText="Order Number" />
                <asp:BoundField DataField="Product" HeaderText="Product" />
                <asp:BoundField DataField="Qty" HeaderText="Qty" />
                <asp:BoundField DataField="UnitAmount" HeaderText="Unit Amount" />
                <asp:BoundField DataField="Value" HeaderText="Line Total" />
                <asp:BoundField DataField="TakenBy" HeaderText="Taken By" />
            </Columns>
            <EditRowStyle BackColor="#999999" />
            <FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" />
            <RowStyle ForeColor="#333333" BackColor="#F7F6F3" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        </asp:GridView>
        <br />
        <asp:Table ID="Table1" runat="server" Height="50px" Width="100%" 
            ForeColor="#333333" GridLines="None">
        <asp:TableHeaderRow EnableTheming="true" BackColor="#5D7B9D" Font-Bold="True" ForeColor="White">
            <asp:TableHeaderCell>Account Ref:</asp:TableHeaderCell>
            <asp:TableHeaderCell>Invoice Ref</asp:TableHeaderCell>
            <asp:TableHeaderCell>Customer Order #</asp:TableHeaderCell>
            <asp:TableHeaderCell>Product</asp:TableHeaderCell>
            <asp:TableHeaderCell>Qty</asp:TableHeaderCell>
            <asp:TableHeaderCell>Unit Amount</asp:TableHeaderCell>
            <asp:TableHeaderCell>Value</asp:TableHeaderCell>
            <asp:TableHeaderCell>Taken By</asp:TableHeaderCell>
        </asp:TableHeaderRow>
        <asp:TableRow ForeColor="#333333" BackColor="#F7F6F3">
            <asp:TableCell><asp:TextBox ID="txtAccountRef" runat="server"></asp:TextBox></asp:TableCell>
            <asp:TableCell><asp:TextBox ID="txtInvoiceRef" runat="server"></asp:TextBox ></asp:TableCell>
            <asp:TableCell><asp:TextBox ID="txtCustOrderNo" runat="server"></asp:TextBox></asp:TableCell>
            <asp:TableCell><asp:TextBox ID="txtProduct" runat="server"></asp:TextBox></asp:TableCell>
            <asp:TableCell><asp:TextBox ID="txtQty" runat="server"></asp:TextBox></asp:TableCell>
            <asp:TableCell><asp:TextBox ID="txtUnitAmount" runat="server"></asp:TextBox></asp:TableCell>
            <asp:TableCell><asp:TextBox ID="txtValue" runat="server"></asp:TextBox></asp:TableCell>
            <asp:TableCell><asp:TextBox ID="txtTakenBy" runat="server"></asp:TextBox></asp:TableCell>
            <asp:TableCell><asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" /></asp:TableCell>
        </asp:TableRow>
        </asp:Table> 
    </fieldset>
    </div>
  </legend>  
</form>
</body>
</html>

The Code Behind

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Data.SqlClient;

namespace TestDataTable
{
    public partial class _Default : System.Web.UI.Page
    {
        internal DataTable myDt = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                myDt = new DataTable();
                myDt = CreateDataTable();
                Session["myDatatable"] = myDt;

                this.GridView1.DataSource = ((DataTable)Session["myDatatable"]).DefaultView;
                this.GridView1.DataBind();
            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtAccountRef.Text.Trim() == "")
            {
                this.lblTips.Text = "You must have an Account Number.";
                return;
            }
            else
            {
                AddDataToTable (
                    this.txtAccountRef.Text.Trim(),
                    this.txtInvoiceRef.Text.Trim(),
                    this.txtCustOrderNo.Text.Trim(),
                    this.txtProduct.Text.Trim(),
                    this.txtQty.Text.Trim(),
                    this.txtUnitAmount.Text.Trim(),
                    this.txtValue.Text.Trim(),
                    this.txtTakenBy.Text.Trim(),
                    (DataTable)Session["myDatatable"]
                );


                this.GridView1.DataSource = ((DataTable)Session["myDatatable"]).DefaultView;
                this.GridView1.DataBind();

                this.txtAccountRef.Text = "";
                this.txtInvoiceRef.Text = "";
                this.txtCustOrderNo.Text = "";
                this.txtProduct.Text = "";
                this.txtQty.Text = "";
                this.txtUnitAmount.Text = "";
                this.txtValue.Text = "";
                this.txtTakenBy.Text = "";
                this.lblTips.Text = "";
            }
        }

        private void AddDataToTable(string AccountRef, string InvRef, string CustOrderNo, string Product, string Qty, string UnitAmount, string Value, string TakenBy, DataTable myTable)
        {
            DataRow row;

            row = myTable.NewRow();

            row["id"] = Guid.NewGuid().ToString();
            row["AccountRef"] = txtAccountRef;
            row["InvRef"] = txtInvoiceRef;
            row["CustOrderNo"] = txtCustOrderNo;
            row["Product"] = txtProduct;
            row["Qty"] = txtQty;
            row["UnitAmount"] = txtUnitAmount;
            row["Value"] = txtValue;
            row["TakenBy"] = txtTakenBy;


            myTable.Rows.Add(row);
        }

        private DataTable CreateDataTable()
        {
            DataTable myDataTable = new DataTable();

            DataColumn myDataColumn;

            myDataColumn = new DataColumn();
            myDataColumn.DataType = Type.GetType("System.String");
            myDataColumn.ColumnName = "id";
            myDataTable.Columns.Add(myDataColumn);

            myDataColumn = new DataColumn();
            myDataColumn.DataType = Type.GetType("System.String");
            myDataColumn.ColumnName = "AccountRef";
            myDataTable.Columns.Add(myDataColumn);

            myDataColumn = new DataColumn();
            myDataColumn.DataType = Type.GetType("System.String");
            myDataColumn.ColumnName = "InvRef";
            myDataTable.Columns.Add(myDataColumn);

            myDataColumn = new DataColumn();
            myDataColumn.DataType = Type.GetType("System.String");
            myDataColumn.ColumnName = "CustOrderNo";
            myDataTable.Columns.Add(myDataColumn);

            myDataColumn = new DataColumn();
            myDataColumn.DataType = Type.GetType("System.String");
            myDataColumn.ColumnName = "Product";
            myDataTable.Columns.Add(myDataColumn);

            myDataColumn = new DataColumn();
            myDataColumn.DataType = Type.GetType("System.String");
            myDataColumn.ColumnName = "Qty";
            myDataTable.Columns.Add(myDataColumn);

            myDataColumn = new DataColumn();
            myDataColumn.DataType = Type.GetType("System.String");
            myDataColumn.ColumnName = "UnitAmount";
            myDataTable.Columns.Add(myDataColumn);

            myDataColumn = new DataColumn();
            myDataColumn.DataType = Type.GetType("System.String");
            myDataColumn.ColumnName = "Value";
            myDataTable.Columns.Add(myDataColumn);

            myDataColumn = new DataColumn();
            myDataColumn.DataType = Type.GetType("System.String");
            myDataColumn.ColumnName = "TakenBy";
            myDataTable.Columns.Add(myDataColumn);

            return myDataTable;
        }

    }
}

Thanks in advance!
Justin

  • 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-20T23:35:34+00:00Added an answer on May 20, 2026 at 11:35 pm

    You forgot the .Text property; use it to assign text of your control:

    row["AccountRef"] = txtAccountRef.Text;
            row["InvRef"] = txtInvoiceRef.Text;
            row["CustOrderNo"] = txtCustOrderNo.Text;
            row["Product"] = txtProduct.Text;
            row["Qty"] = txtQty.Text;
            row["UnitAmount"] = txtUnitAmount.Text;
            row["Value"] = txtValue.Text;
            row["TakenBy"] = txtTakenBy.Text;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In C#/ASP.NET 3.5, I have a DataTable which pulls rows from the database. I
I have ASP.NET web pages for which I want to build automated tests (using
I have asp.net form that contains fields. When I access this window, my javascript
I have an Asp.NET application (VS2008, Framework 2.0). When I try to set a
I have some ASP.NET web services which all share a common helper class they
I have an ASP.NET web application which does the following: Reads an Excel file.
I have a standard ASP.Net DataPager with a standard ListView (using a DataTable as
We have a data driven ASP.NET website which has been written using the standard
I have a problem with my asp.net program. I am doing a Datatable.Compute on
We have asp.net mvc 2 site which allows www and without any subdomain. For

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.