Monday, March 12, 2012

web Form

I've been working with asp.net for all of an hour, so I'm as new as you can be. I'm trying to create a page that lists items from a query and has a text box for data entry. It would basically be like an order page. For example. a list of 20 items with a textbox thet the user can enter an amount. The data would then be entered into another table.

Any help would be greatly appreciated!

Thanks!

Which version of asp.net are you working with, and which IDE?

It's pretty easy to do with some drag and drop steps, which I'll explain as soon as you nail it down a little for me. :)


Thanks for the quick reply! I am using MS Visual Web Developer Express 2005 and/or Dreamweaver8.

Thanks much!


I forgot to mention-I'm using asp.net 2.0


Great! Lets get started then,

Assuming you have your database setup, and it's accessable from your web page, lets start by adding a DataSource.

You can find different types of data sources under the "Data" section in your toolbox on the left hand side of your screen. (default layout).

Just grab it with your mouse and drop it right onto your page. Make sure your in design view.

You'll probably get a wizard asking you if you'd like to configure your data source, and yes, you would. If you dont, there is going to be a little black arrow, in the upper right hand corner of your datasource on your page, surrounded by a white box. Click that, and choose configure data source.

The first thing you want to do make sure as you go through this, is when you get to the Query part of the wizard, click advanced, and choose "Generate INSERT UPDATE and DELETE"

Ok that out and finish the wizard up.

Now, drag a gridview onto your page, you could have used datalist, details view, or several others like the repeater, but we can stick with gridview for now.

Your creating whats called a databound control! You'll get the same black arrow in the upper right hand corner, you want to go ahead and choose your new datasource that we've just created from the list, as its binding data.

If everything was set up properly, you should be able to render your page at this point and have a working gridview that allows you to edit / update and / delete records.

When you get that far, let me know and we'll flesh it out to be more of what your looking for.


Thanks! I have been working with the tutorials and have gotten that far!

Here's what I'm trying to do:

Show item from table "A" here text box here to record quantity (table "B")
Show item from table "A" here text box here to record quantity (table "B")

Etc.

One of the many things I can't figure out is how to start with a new record in table "B" it keeps displaying the data already in the table. Also, if possible I need to record in table "B" the item in table "A" along with the quanity.

I've got it working well in Access using forms and queries, but I've hit a wall here.

Thanks for any help!



I think what you may be looking for instead of a gridview is a "FormView"

This will get you closer to what your looking for.

Add a formview to your page, and in the properties of the formview, change the "DefaultMode" in the Behavior section from "Read only" to "Insert"


Thanks, that was a big help! At least know I know how to enter new data. The only problem I have now is how to populate the second table with a couple of fields in the first table. I display the first table in gridview and the second in form view. I can enter new data in the form view, but I'd like a couple of fields from the selected line in grid view to also be entered in the second table (form view) Is there a way to better tie the two together?

Thanks!


I'm not quite sure what your trying to do, I've re-read it a few times and dont get it. Call me thick today. lol.

Let me understand if I get it at all.

Part 1.

You have two tables, Table A, and Table B

You have a form that enters data into table A, that's working somewhat as intended

You have data in Table B, that you also want to be added to table A when the form is submitted, example below:

Form Fields

Name

Email

Grid View rows

USA Midwest

Canada Alberta

The end result you'd like to end up with is table A having

John Smith,john@.smith.com, USA, Midwest

Did I put that together correctly?


Yes! I think you got it! Here's what I'm trying to do:

User ID

Code# Description Amount

50398 Orchard Fruit Snacks

Etc.

The code and description would come from table 1; The amount would be stored in table 2.

I'd like to have them enter the amounts for each line and then have the amount, the code number and the user ID all stored in table 2. I'm hoping to get the user ID from the login page, but that's a long way off at this point.

I really appreciate all your help-I've been working on this for 3 days, 12 hours a day and have made progress, but your advice saves me about 6 hours per reply!

Thanks!


Sorry about the formatting of the last post-it messed up the html I inserted

It should look more like this:

User ID

Code# Description Amount

50398 Orchard Fruit snacks text box for amount

Hopefully this will be clearer!

Thanks


Ok, I think where your getting hung up at, is your trying to do WAY to much through creative code, and forgeting the main point of a relational database.

I'll expound here.

Instead of trying to store ALL the information in one table, see if this makes any sense.

Table 1: Products

Code# Description Price Weight

50398 Orchard $5.95 1 pound

Table 2: Orders

Code# User Name Quantity Date

50398 Smith 10 1/24/2006 1:24:00pm

_________________________________________________

With this example, you can use the relational nature of a database, to refer back to your products table using the Code#.

So when you do an orders lookup, you can extrapolate what was ordered, without having to duplicate it over and over in your db.


Yes, that's how I have it setup!

What I'l like to have happen is that the user enters the quantity and the code number, user and quantity all get entered in table 2. So a page might look like this;

User

Code Description Price Amount
Table1data Table1data Table1data text box for amount

then when the user enters the amount and hits 'Insert", the 3 pieces of data from table 1 and the new data entered into the text box all go into table 2.

Thanks so much for sticking with this!


You dont need to move data from 1 table to another. You need to use a relational database setup, to refer back to that data.

In this case, the relational part is the code number. In my example above the way it would work is...

Mr. Smith visits your website, he clicks a button next to Orchard Fruit Snacks that says "Buy".

Your app moves to a page that allows him to enter the amount (quantity) he wants to order, your app moves to a confirmation page.

At this point, we have the code number (because the button was tied to the item), we have the User Name (because the user is logged in.), and we have the quantity they want to order.

There is NO reason to store the items information in table 2, the only thing you need to store is the code for the item.

When the user presses submit, your second table stores

Code UserName Quantity OrderDate

Everything else at that point can be calculated. You dont need to store a price or description, and you do need to store a username. I would actually recomend you make your User's relational too, so that each user has an ID, and information associated with them. For example

Table Users:

User_ID First Name Last Name Address email phone

1 John Smith 123 anywhere john@.smith.com 123-456-7890

Then, you store the information like this in your orders table

Code UserID Quantity OrderDate

By doing it that way, you can store a lot of information about the users of your site, without having to duplicate it every time they make an order.


Yes, That's exactly what I'm trying to do. I don't want to store duplicate data , just the code, the used id and the amount. I was hoping to be able to do it without having to send the user to another page each time by hitting a "buy' button. There would be multiple rows, each with the "products" data and an "amount" textbox. When the entered the amount in the box and hit "insert" only the code, usedID and amount would be entered into table 2-no duplicate data.

Code Description Price Amount
Table1data Table1data Table1data text box for amount I NSERT
Table1data Table1data Table1data text box for amount INSERT
Table1data Table1data Table1data text box for amount I NSERT
Table1data Table1data Table1data text box for amount INSERT

I think this is like your example, but without going to the second page. In your example, how does the code number and userID get entered into table 2? That seems to be the thing that's hanging me up.

Thanks!!!!!

0 comments:

Post a Comment