I'm working through the MCAD training, and can't seems to get a dropdownlist to populate from a cached dataset:
**********
Here's the code on the first page:
Private Sub Page_Load(....)
If Not IsPostBack Then
AddtoCache("adptCalls", DA1)
AddtoCache("adptContactTypes", DA2)
AddtoCache("adptContacts", DA3)
'Fill data sets and add them to Cache
DA1.Fill(DsCalls1)
AddtoCache("DSCalls", DsCalls1)
DA2.Fill(DsContactTypes1)
AddtoCache("DSContactTypes", DsContactTypes1)
DA3.Fill(DsContacts1)
AddtoCache("DSContacts", DsContacts1)
End If
End Sub
Sub AddtoCache(ByVal Name As String, ByVal Item As Object)
'if item already in cache, simply return
If Not IsNothing(Cache(Name)) Then Return
'Otherwise cache item for 20min w/ sliding expiration
Cache.Add(Name, Item, Nothing, DateTime.MaxValue, System.TimeSpan.FromMinutes(20), Caching.CacheItemPriority.Default, Nothing)
End Sub
**********
The second page has:
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' Get the Cached variables.
adptContacts = Cache("adptContacts")
dsContacts = Cache("dsContacts")
dsContactTypes = Cache("dsContactTypes")
If Not IsPostBack Then
' Bind to data -- populates lists.
drpContactTypes.DataSource = dsContactTypes
drpContactTypes.DataTextField = "ContactType"
drpContactTypes.DataValueField = "ContacTypeID"
drpContactTypes.DataBind()
drpStates.DataBind()
End If
' If there was an unhandled error, display it.
If Session("Error") <> "" Then
litStatus.Text = Session("Error")
' Reset the error message.
Session("Error") = Nothing
End If
End Sub
**********
Here's the code on the first page:
Private Sub Page_Load(....)
If Not IsPostBack Then
AddtoCache("adptCalls", DA1)
AddtoCache("adptContactTypes", DA2)
AddtoCache("adptContacts", DA3)
'Fill data sets and add them to Cache
DA1.Fill(DsCalls1)
AddtoCache("DSCalls", DsCalls1)
DA2.Fill(DsContactTypes1)
AddtoCache("DSContactTypes", DsContactTypes1)
DA3.Fill(DsContacts1)
AddtoCache("DSContacts", DsContacts1)
End If
End Sub
Sub AddtoCache(ByVal Name As String, ByVal Item As Object)
'if item already in cache, simply return
If Not IsNothing(Cache(Name)) Then Return
'Otherwise cache item for 20min w/ sliding expiration
Cache.Add(Name, Item, Nothing, DateTime.MaxValue, System.TimeSpan.FromMinutes(20), Caching.CacheItemPriority.Default, Nothing)
End Sub
**********
The second page has:
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' Get the Cached variables.
adptContacts = Cache("adptContacts")
dsContacts = Cache("dsContacts")
dsContactTypes = Cache("dsContactTypes")
If Not IsPostBack Then
' Bind to data -- populates lists.
drpContactTypes.DataSource = dsContactTypes
drpContactTypes.DataTextField = "ContactType"
drpContactTypes.DataValueField = "ContacTypeID"
drpContactTypes.DataBind()
drpStates.DataBind()
End If
' If there was an unhandled error, display it.
If Session("Error") <> "" Then
litStatus.Text = Session("Error")
' Reset the error message.
Session("Error") = Nothing
End If
End Sub