How to use variable instead of session

S

staeri

I use the following code in OnRowDataBound for getting the column sum
in a GridView:

Protected Sub dg(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Session("intAccountGroup") =
DataBinder.Eval(e.Row.DataItem, "AccountGroup")
End If

If e.Row.RowType = DataControlRowType.Footer Then
Dim txtSumB As TextBox =
CType(e.Row.FindControl("txtSumB"), TextBox)
txtSumB.Text = Generic_db.GetValue("SELECT Sum(Budget) FROM
vwOverview WHERE AccountGroup=" & Session("intAccountGroup") & " And
Positions=4")
End If
End Sub

I've been trying to replace the session value above with a variable but
it doesn't work because it doesn't contain any value for some reason. I
still have the feeling that there is some way to use a variable instead
of the session. Can someone please help me?

Regards,

S
 
J

Jose Rodriguez

S, have you considered using Viewstate instead of session for this case?, if
you still have to use session do a function like this and see if that helps

Protected Sub SetSession(ByVal keyName As String, ByVal ObjectToStore As
Object)

Dim context As System.Web.HttpContext = System.Web.HttpContext.Current()

Dim state As System.Web.SessionState.HttpSessionState

state = context.Session()

If Not IsNothing(ObjectToStore) Then

state.Item(keyName) = ObjectToStore

End If

End Sub

Protected Function GetSession(ByVal keyName As String) As Object

Dim context As System.Web.HttpContext = System.Web.HttpContext.Current()

Dim sessionItem As Object = context.Session.Item(keyName)

GetSession = sessionItem

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top