Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session and datagrids

Status
Not open for further replies.

rac55

Programmer
Jul 1, 2003
62
AU
Hi

Does anyone know how to add a session to a datatgrid? I have a shopping basket and each time a user selscts an item, the item id is passed a session, but it is only holding one value. I have tried numerous ways but can't seem to get it working. My code is;

Session("ItemID") = Request.QueryString("titleid")

to retrieve the session:
Public Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Session("ItemID") Is Nothing Then

If Not Page.IsPostBack Then
BindData()
End If

Dim arr As New ArrayList

Dim i As Integer


TextBox1.Text = Session("ItemID")


Dim dr As SqlDataReader
Dim MyCommand As SqlCommand

Dim dv As DataView

dv = Cache("trolley")

If dv Is Nothing Then

Dim MyConnection As SqlConnection = New SqlConnection("server=(local); trusted_connection=true; database=Ecommerce_RachelTracey")
'Data Grid for books
Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM tblCustomer CROSS JOIN tblCatalogue WHERE (tblCatalogue.ItemID = '" & Session("ItemID") & "') AND (tblCustomer.EmailAddress = '" & User.Identity.Name & "')", MyConnection)

Dim ds As New DataSet
da.Fill(ds, "tblCustomer")

dv = New DataView(ds.Tables("tblCustomer"))
Cache("trolley") = dv

End If

dsTrolley.DataSource = dv
dsTrolley.DataBind()

Else
Response.Write("Sorry you have not ordered any items yet")
End If

End Sub
 
You can store any serializable object in a session. You can, for instance, use a DataTable.

Instead of adding a single ID to the session, you can retrieve the table you stored in the session, add the ID to the table, then re-store the new table in the session.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top