Hi.
I am new at this and working with a web-project using Microsoft Visual Studio, and need some help quickly as I am stuck with a problem and I am running out of time. My project is making a web-based bookstore. I have made several pages, and on my start-page I have pictures of some of the books the store is selling. Under each book I have a button: <buy> and when the user clicks this button the book is supposed to be put in the shopping cart. The name of the book, the isbn and the price is retrieved from my database through a SQLDataSource, and is shown on the page in a FormView. My problem is writing the code that gets the title, isbn and price from the FormView and sends it to the shopping cart. I have a search page where I use a GridView, and the code I use there is like this:
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
Dim row As GridViewRow
Dim isbn As String
Dim title As String
Dim amount As Integer
Dim price As Double
Dim t As TextBox
Dim p As Label
Dim totalprice As Double
row = GridView1.SelectedRow
t = CType(row.Cells(8).Controls(1), TextBox)
amount = CInt(t.Text)
p = CType(row.Cells(3).Controls(1), Label)
pris = CDbl(p.Text) * amount
isbn = row.Cells(0).Text
title = row.Cells(1).Text
If amount = 0 Then
Server.Transfer(isbn & ".aspx")
Else
Dim shoppingcart As New Data.DataTable
shoppingcart = CType(Session("cart"), Data.DataTable)
Dim newrow As Data.DataRow
newrow = shoppingcart.NewRow
newrow(0) = isbn
newrow(1) = title
newrow(2) = amount
newrow(3) = price
shoppingcart.Rows.Add(newrow)
Session("cart") = shoppingcart
totalprice = Session.Item("TotalPrice")
totalprice = totalprice + price
Session.Add("TotalPrice", totalprice)
Server.Transfer("shoppingcart.aspx")
End If
End sub
This code does the same thing as I wish to do with the FormView, my problem is finding the code that works for a FormView instead of a GridView. Can I use the same code, but just make some changes? And if so, what changes has to be made for this code to work with the FormView?
Live and learn!