How to use variable instead of session

  • Thread starter Thread starter staeri
  • Start date Start date
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
 
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
 
Back
Top