Solved

asp.net session declaration

Posted on 2008-11-03
7
803 Views
Last Modified: 2013-11-07
i want to store a dataset value in a session variable but keep getting the value returned as false when i try and write it to the page, when i write the dataset value to the page it works fine but trying to store in the session is the problem, i have pasted the code below, i use classic asp more so this is where i am probably going wrong, i know there are 3 different types of session in .net but not sure how write them correctly.

<p><%# Session("finalu") =  DataSet1.FieldValue("UserID", Container) %></p>
<p><%= session("fianlu")%></p>
0
Comment
Question by:ckawebcreation
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 22867601
well what language are you using...if it's vb, i think you have to use the Session.Add

if it's c# i think you can just use Session["fadfsd"] =
0
 
LVL 2

Expert Comment

by:vbsquickresponse
ID: 22867816
here code in C#

to store dataset in session  variable and read from session variable to attach into gridview.

Make sure you use this.DataBind() to bind dataset to gridview control
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataSet ds = ProductsDataAccess.GetProductByCategory(1);
        Session["MyDataSet"] = ds;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        DataSet ds = (DataSet)Session["MyDataSet"];
        GridView1.DataSource = ds.Tables["Products"];
        GridView1.DataBind();
    }

Open in new window

0
 

Author Comment

by:ckawebcreation
ID: 22868434
hi vbsquickresponse:

i am using vb though??
0
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

 
LVL 2

Expert Comment

by:vbsquickresponse
ID: 22868874
Logic would be same only the syntax would be difference...

//set to session variable
Session("varname") = value

//read from session varible
Session.Item("varname")

sorry, not able to paste extact code becz I never worked on vb.net
0
 
LVL 2

Accepted Solution

by:
vbsquickresponse earned 100 total points
ID: 22869082
here first time I tried code in VB.net


    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ds As DataSet = ProductDataAccess.getProductsbyCategoryID(1)
 
        Session("MyDataSet") = ds
    End Sub
 
    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim ds As DataSet = Session("MyDataSet")
        GridView1.DataSource = ds.Tables("Products")
        GridView1.DataBind()
    End Sub

Open in new window

0
 

Author Comment

by:ckawebcreation
ID: 22870920
hi vbsquickresponse:

thanks for the code,

couldn't get that working, surely there must be a way of assigning a value to a session by using a simple statement lke <p><%# Session("finalu") =  DataSet1.FieldValue("UserID", Container) %></p>
i can get the value for the session from a Request.QueryString("Username") either from the current page.

i am using a post method on this page so have struggled to access the Request.QueryString("Username") from my next page that is why i am trying to put it in a session variable so i can access it on the next page.

cheers
0
 

Author Comment

by:ckawebcreation
ID: 22871502
got sorted guys, messed around with url params, cheers vbsquickresponse: and silemone:
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question