J
John Kotuby
Hi all,
This is the first time I have tried storing a datatable into a session
variable and then later bind it to a DropDownList.
The List contains about 2600 entries of values and text. It represents a
lookup table.
I am trying to not use SessionState on this particular page as that appears
to make the page size too large and affects perfomance.
Upon intitial page load I am running a SQL Server select which uses a
dataAdapter to fill the DataTable.
I then attempt to save the datatable to Session and finally bind the
datatable to the lstOwner (DropDownList).
Here is that code:
-----------------------------------------------------------------------
MyAdapter.SelectCommand = MyCommand
MyAdapter.Fill(OwnerTable)
' Add the Ownertable to session vars for later use
Session.Add("dtOwners", OwnerTable)
'Specify which field is to be Value and wich field is to be Text
Me.lstOwner.DataTextField = "company"
Me.lstOwner.DataValueField = "ownercode"
' Now bind the table to the DropDownList
Me.lstOwner.DataSource = OwnerTable
Me.lstOwner.DataBind()
------------------------------------------------------------------------
Upon postback I attempt to reference the Session variable to re-load the
lookup list without running another SQL query.
------------------------------------------------------------------------
If Page.IsPostBack Then
'Check existance of ddlOwners session var and load the Owners into
lstOwners
If Not Session("dtOwners") Is Nothing Then
lstOwner.DataSource = CType(Session("dtOwners"), DataTable)
lstOwner.DataBind()
Else
'Run the SQL query
GetOwners()
End If
End If
---------------------------------------------------------------------
What I end up with in lstOwners are 2600 entries of
"System.Data.DataRowView".
Can anyone tell me what I am doing wrong? I thought I was following the
example of some code that was posted by Stephen Cheng from Microsoft, but
apparently I am making a mistake.
Thanks for any help...
This is the first time I have tried storing a datatable into a session
variable and then later bind it to a DropDownList.
The List contains about 2600 entries of values and text. It represents a
lookup table.
I am trying to not use SessionState on this particular page as that appears
to make the page size too large and affects perfomance.
Upon intitial page load I am running a SQL Server select which uses a
dataAdapter to fill the DataTable.
I then attempt to save the datatable to Session and finally bind the
datatable to the lstOwner (DropDownList).
Here is that code:
-----------------------------------------------------------------------
MyAdapter.SelectCommand = MyCommand
MyAdapter.Fill(OwnerTable)
' Add the Ownertable to session vars for later use
Session.Add("dtOwners", OwnerTable)
'Specify which field is to be Value and wich field is to be Text
Me.lstOwner.DataTextField = "company"
Me.lstOwner.DataValueField = "ownercode"
' Now bind the table to the DropDownList
Me.lstOwner.DataSource = OwnerTable
Me.lstOwner.DataBind()
------------------------------------------------------------------------
Upon postback I attempt to reference the Session variable to re-load the
lookup list without running another SQL query.
------------------------------------------------------------------------
If Page.IsPostBack Then
'Check existance of ddlOwners session var and load the Owners into
lstOwners
If Not Session("dtOwners") Is Nothing Then
lstOwner.DataSource = CType(Session("dtOwners"), DataTable)
lstOwner.DataBind()
Else
'Run the SQL query
GetOwners()
End If
End If
---------------------------------------------------------------------
What I end up with in lstOwners are 2600 entries of
"System.Data.DataRowView".
Can anyone tell me what I am doing wrong? I thought I was following the
example of some code that was posted by Stephen Cheng from Microsoft, but
apparently I am making a mistake.
Thanks for any help...