Solved

asp.net session declaration

Posted on 2008-11-03
7
807 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
Industry Leaders: 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!

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 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