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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:42:38+00:00 2026-06-18T20:42:38+00:00

Hello I have a table with a few textboxes and when a user clicks

  • 0

Hello I have a table with a few textboxes and when a user clicks the button it gets added to a gridview. It worked fine with Shared dtValues As New DataTable() but I ran into other issues so I changed it to Public …. On the button press is where I get the error Column ‘Qty’ does not belong to the table. Any suggestions?

aspx

                <asp:Table ID="tblPrice" runat="server" GridLines ="Both">
                <asp:TableRow>
                    <asp:TableCell>QTY.</asp:TableCell>
                    <asp:TableCell>MATERIAL</asp:TableCell>
                    <asp:TableCell>COST</asp:TableCell>
                    <asp:TableCell>PRICE</asp:TableCell>
                    <asp:TableCell>TOTAL</asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell>
                         <asp:TextBox ID="txtQty" runat="server" Width="40" Text = "1"></asp:TextBox>
                    </asp:TableCell>
                    <asp:TableCell>
                        <asp:TextBox ID="txtMaterials" runat="server"></asp:TextBox>
                    </asp:TableCell>
                    <asp:TableCell>
                        <asp:TextBox ID="txtCost" runat="server" Width="125" Text = "0" ></asp:TextBox>
                        <asp:MaskedEditExtender ID="meeCost1" runat="server" Mask="99,999,999.99" DisplayMoney="Left" TargetControlID="txtCost" MaskType="Number">
                        </asp:MaskedEditExtender>
                    </asp:TableCell>
                    <asp:TableCell>
                        <asp:TextBox ID="txtPrice" AutoPostBack="true" runat="server" Width="125" Text = "0" OnTextChanged = "PriceChange"></asp:TextBox>
                        <asp:MaskedEditExtender ID="meePrice1" runat="server" Mask="99,999,999.99" DisplayMoney="Left" TargetControlID="txtPrice" MaskType="Number">
                        </asp:MaskedEditExtender>
                    </asp:TableCell>
                    <asp:TableCell>
                        <asp:Label ID="lblTotal" runat="server" Text="$0.00"></asp:Label>
                    </asp:TableCell>                
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell>
                        <asp:Button ID="btnAddPurchase" runat="server" Text="Add Purchase" OnClick="btnAddPurchase_Click"  />
                    </asp:TableCell>
                </asp:TableRow>
            </asp:Table>
            <br />
            <asp:GridView ID="gvPurchases" runat="server" AutoGenerateColumns="False" 
                AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" 
                AutoGenerateSelectButton="True" >
            </asp:GridView>

code Behind

Public Class _Default
Inherits System.Web.UI.Page
Public dtValues As New DataTable()

Protected Sub Page_Load(sender As Object, e As EventArgs)
    If Not IsPostBack Then
        CreateDataTable()
    End If
End Sub
 Protected Sub CreateDataTable()
    dtValues.Columns.Add(New DataColumn("Qty"))
    dtValues.Columns.Add(New DataColumn("Materials"))
    dtValues.Columns.Add(New DataColumn("Cost"))
    dtValues.Columns.Add(New DataColumn("Price"))
    dtValues.Columns.Add(New DataColumn("Total"))
End Sub

Protected Sub btnAddPurchase_Click(sender As Object, e As EventArgs)

    Dim drValues As DataRow = dtValues.NewRow()

    drValues("Qty") = txtQty.Text
    drValues("Materials") = txtMaterials.Text
    drValues("Cost") = txtCost.Text
    drValues("Price") = txtPrice.Text

    dtValues.Rows.Add(drValues)

    gvPurchases.DataSource = dtValues
    gvPurchases.DataBind()

    txtQty.Text = "1"
    txtMaterials.Text = ""
    txtCost.Text = "0"
    txtPrice.Text = "0"
    lblTotal.Text = "$0.00"
End Sub
  • 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-18T20:42:39+00:00Added an answer on June 18, 2026 at 8:42 pm

    It is happening because the table is created only on initial page load and when it is posted back via button click, table is again initialized but with no columns since IsPostBack is true in Page_Load event. So, by removing the IsPostBack condition, table object is instantiated with columns for every page request.

    Protected Sub Page_Load(sender As Object, e As EventArgs)                 
        CreateDataTable()
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Table, TextArea and Button, when a user type in the Textarea
Hello I have a table on which I have denied SELECT privs to a
Hello i have a products table that contains normal products and configurable product It
I have UserComments table like this : 1 | Frank | hello world 2
I have a table like this: someid somestring 1 Hello 1 World 1 Blah
hello all this seems to be my problem I have a table in mysql
I have something similar to that: <table> <tr> <td>Hello,<br/>World!</td> </tr> </table> Both lines Hello,
http://www.koolfree.com/ImageUpload/uploads/1340729929.jpg (Table Image) Hello, I have linked to an Image (because stackoverflow was not
Hello I have like this 2 tables class User public int UserId{get;set;} { ....
Hello I have a table with the tenure (integer, calculated in weeks) of employees

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.