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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:34:31+00:00 2026-05-21T04:34:31+00:00

I am building a ASP.NET page which is an Sales Order Processing Form I

  • 0

I am building a ASP.NET page which is an Sales Order Processing Form I have two Last issues that due to my lack of experience in the language I am struggling with hopefully you can help.

Issue 1 – I have a field <asp:DropDownList runat="server" ID="txtProduct"></asp:DropDownList> that is pulling from a database table Called Products to populate its options list. I need to automatically pull the SalesPrice value and insert it into the txtUnitAmount field based on the selection of the Product.

Issue 2 – Once the form has been filled and there are records in the DataTable I then need to insert all of the rows into the Database table SalesOrders when a user clicks a button.

My ASPX code (in full)

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SOPOrderEntry.aspx.cs" Inherits="CRM2Sage.SOPOrderEntry1" %>

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>

<!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">
<link rel="Stylesheet" type="text/css" href="stylesheet.css" />
    <title>CRM2Sage - SOP Entry Form</title>
    <style type="text/css">
        .style1
        {
            width: 100%;
            float: left;
            border-style: solid;
            border-width: 1px;
        }
    </style>
    <script type="text/javascript">
        function q_multi_p(form) {
            q = eval(form.txtQty.value)
            p = eval(form.txtUnitAmount.value)
            t = q * p
            form.txtValue.value = t
        }
    </script>
</head>
<body style="padding: 0; margin: 0;">
<div style="width: 1170px; margin: 0 auto;">
    <form id="form1" runat="server">
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:CRM2Sage %>"
    SelectCommand="SELECT [AccountRef], [Name], [Add1], [Add2], [Add3], [Add4], [Add5], [ContactName], [Telephone], [Terms] FROM [Customers]">
    <SelectParameters>
        <asp:Parameter DefaultValue="1" Name="AccountRef" Type="String" />
    </SelectParameters>
    </asp:SqlDataSource> 
    <div style="width: 1170px; height: 211px;">
        <table align="right" cellpadding="0" class="style1">
            <tr>
                <td>
    <asp:DetailsView ID="DetailsView1" runat="server" Height="100%" Width="585px" 
        AutoGenerateRows="False" DataSourceID="SqlDataSource1" 
        EnableModelValidation="True" HorizontalAlign="Left" CellPadding="4" ForeColor="#333333" 
                        GridLines="None">
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
        <EditRowStyle BackColor="#999999" />
        <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
        <Fields>
            <asp:BoundField DataField="AccountRef" HeaderText="Account Ref" 
                SortExpression="AccountRef" />
            <asp:BoundField DataField="Name" HeaderText="Company Name" 
                SortExpression="Name" />
            <asp:BoundField DataField="Add1" HeaderText="Address" SortExpression="Add1" />
            <asp:BoundField DataField="Add2" SortExpression="Add2" />
            <asp:BoundField DataField="Add3" HeaderText="City" SortExpression="Add3" />
            <asp:BoundField DataField="Add4" HeaderText="County" SortExpression="Add4" />
            <asp:BoundField DataField="Add5" HeaderText="Post Code" SortExpression="Add5" />
            <asp:BoundField DataField="ContactName" HeaderText="Contact" 
                SortExpression="ContactName" />
            <asp:BoundField DataField="Telephone" HeaderText="Telephone" 
                SortExpression="Telephone" />
            <asp:BoundField DataField="Terms" HeaderText="Credit Terms" 
                SortExpression="Terms">
            <HeaderStyle CssClass="lbl" />
            <ItemStyle CssClass="row" />
            </asp:BoundField>
        </Fields>
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    </asp:DetailsView>
                </td>
                <td>
                    <table>
                    <tr>
                    <td><asp:Label ID="OrderNoLabel" runat="server" Text="Customer Order No."></asp:Label></td>
                    <td><asp:TextBox ID="OrderNoText" runat="server" 
                            ontextchanged="OrderNoText_TextChanged"></asp:TextBox></td>
                    </tr>
                    <tr>
                    <td><asp:Button ID="GenInvRef" runat="server" Text="Gen Invoice Ref" 
                            onclick="GenInvRef_Click" /></td>
                    <td><asp:TextBox ID="InvRefText" runat="server" 
                            ontextchanged="InvRefText_TextChanged"></asp:TextBox></td>
                    </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
    <div style="width: 100%; border: 2px Groved #666; background-color: #FFF; height: 100%; padding: 15px;">
    <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="No Order Lines Created Yet!" 
            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>
        <div style="margin: 0 auto; position: relative;">  
            <asp:Table ID="Table1" runat="server" Width="1158px" 
                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" CssClass="ContactSmallTextField" ReadOnly="True"></asp:TextBox></asp:TableCell>
                <asp:TableCell><asp:TextBox ID="txtInvoiceRef" runat="server" CssClass="ContactSmallTextField"></asp:TextBox ></asp:TableCell>
                <asp:TableCell><asp:TextBox ID="txtCustOrderNo" runat="server" CssClass="ContactSmallTextField"></asp:TextBox></asp:TableCell>
                <asp:TableCell><asp:DropDownList runat="server" ID="txtProduct"></asp:DropDownList></asp:TableCell>
                <asp:TableCell><asp:TextBox ID="txtQty" runat="server" CssClass="ContactExtTextField" onChange="javascript:q_multi_p(this.form)"></asp:TextBox></asp:TableCell>
                <asp:TableCell><asp:TextBox ID="txtUnitAmount" runat="server" CssClass="ContactSmallTextField"></asp:TextBox></asp:TableCell>
                <asp:TableCell><asp:TextBox ID="txtValue" runat="server" CssClass="ContactSmallTextField"></asp:TextBox></asp:TableCell>
                <asp:TableCell><asp:TextBox ID="txtTakenBy" runat="server" CssClass="ContactSmallTextField"></asp:TextBox></asp:TableCell>           
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell><asp:Button ID="btnAdd" runat="server" Text="Add Order Line" OnClick="btnAdd_Click" CssClass="btn" /></asp:TableCell>
            </asp:TableRow>
            </asp:Table>
        </div>
    </fieldset>
    </div>
    </form>
</div>
</body>
</html>

My CS Code in Full

using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Web.Security;
using System.Web.Configuration;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace CRM2Sage
{
    public partial class SOPOrderEntry1 : 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();

            }
            getAccountRef();
            Fill1();
        }



        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(),
                    (string)Request.Form["InvRefText"].ToString(),
                    (string)Request.Form["OrderNoText"].ToString(),
                    (string)Request.Form["txtProduct"].ToString(),
                    //this.txtProduct.Text.Trim(),
                    this.txtQty.Text.Trim(),
                    (string)Request.Form["txtUnitAmount"].ToString(),
                    //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.SelectedItem.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"] = AccountRef;
            row["InvRef"] = InvRef;
            row["CustOrderNo"] = CustOrderNo;
            row["Product"] = Product;
            row["Qty"] = Qty;
            row["UnitAmount"] = UnitAmount;
            row["Value"] = Value;
            row["TakenBy"] = txtTakenBy.Text;


            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;
        }

        public void Fill1()
        {
            string connectionString = WebConfigurationManager.ConnectionStrings["CRM2Sage"].ConnectionString;
            using (SqlConnection _con = new SqlConnection(connectionString))
            using (SqlCommand cmd = new SqlCommand("SELECT * FROM Products", _con))
            {
                cmd.Connection.Open();

                SqlDataReader ddlValues;
                ddlValues = cmd.ExecuteReader();

                txtProduct.DataSource = ddlValues;
                txtProduct.DataValueField = "Description";
                txtProduct.DataTextField = "Description";
                txtProduct.DataBind();

                cmd.Connection.Close();
                cmd.Connection.Dispose();
            }
        }

        public void getAccountRef()
        {
            string getAccountRef = (string)Request.QueryString["AccountRef"].ToString();
            SqlDataSource1.SelectParameters[0].DefaultValue = getAccountRef;
            txtAccountRef.Text = getAccountRef;
        }

        public void getOrderNo()
        {
            string getOrderNo = (string)Request.Form["OrderNoText"].ToString();
            txtCustOrderNo.Text = getOrderNo;
        }

        protected void OrderNoText_TextChanged(object sender, EventArgs e)
        {
            getOrderNo();
        }

        private string GenerateId()
        {
            long i = 1;
            foreach (byte b in Guid.NewGuid().ToByteArray())
            {
                i *= ((int)b + 1);
            }
            return string.Format("{0:x}", i - DateTime.Now.Ticks);
        }

        protected void GenInvRef_Click(object sender, EventArgs e)
        {
            string GenInvRef = GenerateId();
            InvRefText.Text = GenInvRef;
        }

        public void getInvRef()
        {
            string getInvRef = (string)Request.Form["InvRefText"].ToString();
            txtInvoiceRef.Text = getInvRef;
        }

        protected void InvRefText_TextChanged(object sender, EventArgs e)
        {
            getInvRef();
        }

        //public void Fill2()
        //{
        //    string getProdValue = WebConfigurationManager.ConnectionStrings["CRM2Sage"].ConnectionString;
        //    using (SqlConnection _con = new SqlConnection(getProdValue))
        //    using (SqlCommand cmd = new SqlCommand("SELECT SalesPrice FROM Products WHERE Description = '" + txtProduct + "'", _con))
        //    {
        //        cmd.Connection.Open();
        //        var unitPrice = cmd.ExecuteScalar();
        //        txtUnitAmount.Text = unitPrice.ToString();
        //        cmd.Connection.Close();
        //        cmd.Connection.Dispose();
        //    }           
        //}

        //protected void txtProduct_OnSelectedIndexChanged(object sender, EventArgs e)
        //{
        //    Fill2();
        //}

    }
}

I think with a bit of help and guidance I will be done and ever so grateful this will also stand me in good sted for further projects, thanks in advance to everyone who answers I will of course give full props to everyone who helps out.

In the mean time a thank you to @Slappy, @Nick & @MikeEast and the other many who have been really helpful thus far.

Best

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-21T04:34:32+00:00Added an answer on May 21, 2026 at 4:34 am

    As I can’t write the entire code, so only giving you some hints.

     1. Create a class with the field name you want to insert into you DB. 
        Like for Sales order, whatever fields you have in your form, 
        create properties for the same.
    
     2. Bind the grid and Dropdowns from the database using the datatable.
    
     3. Put a hidden field on the form to detect insert or update process
    
     4. On selection chnage of grid or dropdown fill the form fields, 
        you have for sales order. By extracting the rows from the datatable 
        and fill it to textboxes.
    
     5. While save button click , create a method that will be used for filling
        up the SalesOrder Class object. pass this object to data layer, extract 
       the properties and pass it as parameter in your AddUpadte query.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an ASP.NET MVC application with a form that needs validation. The majority
I'm building a form in ASP.NET MVC3 + Razor that posts to a PHP
I'm building an asp.net page that uses a page method call from jquery. This
In building an ASP.NET 3.5 WAP, I'm always frustrated by the feeling that no
Say I'm building an ASP.Net class that inherits from IHttpHandler , should I wire
I'm building an ASP.Net MVC website. Rather than have everything in one project, I've
I am building an Asp.net MVC site where I have a fast dedicated server
I am building ASP.NET 2.0 websites and currently I some home grown assemblies for
I'm building an ASP.NET web application, and all of my strings are stored in
I'm am building my asp.net web application using MVC (Preview 5), and am also

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.