Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to cache dataset for 10 dropdownlists

Status
Not open for further replies.

lanm

Programmer
Jul 7, 2005
244
US
Here's my code. I can't get the ddls to populate when the pages loads. I've only got two built in the code so far, but we want to be able to support 5-10 when the code goes live. I know the sprocs work, since since I tried using cache for the datasets, the ddls wouldn't populate.

The dropdownlists that don't populate are:
KSddlNewName
KSddlNewName2
KSddlNewP3ResCode
KSddlNewP3ResCode2


Imports System
Imports System.Collections
Imports System.DBNull
Imports System.Data.SqlClient
Imports System.CLSCompliantAttribute
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Data.OleDb
Imports System.IO
Imports Microsoft.VisualBasic
Imports System.Configuration

Public Class AddMulitpleResources
Inherits System.Web.UI.Page


Dim DSNewName As DataSet
Dim DSNewP3ResCode As DataSet
Public arrFY As String() = {"05", "06", "07", "08", _
"09", "10", "11", "12", "13", "14", "15", "16", "17", _
"18", "19", "20"}

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
'Make SQL Statement to populate New Name ddl
Dim strSQLNewName As String = "usp_SARes_KSddlNewName"

sCon.Open()
Dim cmd As New SqlCommand(strSQLNewName, sCon)
cmd.CommandType = CommandType.StoredProcedure
Dim DANewName As New SqlDataAdapter
DANewName.SelectCommand = cmd
Dim DSNewName As New DataSet
DANewName.Fill(DSNewName)

'************************************

If Cache("DSNewName") Is Nothing Then
CacheDS("DSNewname", DSNewName)
End If


'Make SQL Statement to populate the second ddl, KSddlNewP3ResourceCode
Dim strSQLNewP3 As String = "usp_SARes_KSddlNewP3ResourceCode"

Dim cmdP3 As New SqlCommand(strSQLNewP3, sCon)
cmdP3.CommandType = CommandType.StoredProcedure
Dim DA As New SqlDataAdapter
DA.SelectCommand = cmdP3
Dim DSNewP3ResCode As New DataSet
DA.Fill(DSNewP3ResCode)

If Cache("DSNewP3ResCode") Is Nothing Then
CacheDS("DSNewP3ResCode", DSNewP3ResCode)
End If


'**************************************
sCon.Close()
Call Build_KSddlNewName()
Call buildKSddlNewP3ResourceCode()
Call BuildFYddls()
End If
End Sub
Sub CacheDS(ByVal Name As String, ByVal Item As Object)

Cache.Add(Name, Item, Nothing, DateTime.MaxValue, System.TimeSpan.FromMinutes(40), _
Caching.CacheItemPriority.Default, Nothing)


End Sub
Sub BuildFYddls()
KSFYddl.DataSource = arrFY
KSFYddl.DataBind()
KSFY2ddl.DataSource = arrFY
KSFY2ddl.DataBind()
End Sub

Public Sub Build_KSddlNewName()

KSddlNewName.DataSource = DSNewName
KSddlNewName.DataTextField = "Expr4"
KSddlNewName.DataValueField = "ZNumber"
KSddlNewName.DataBind()
KSddlNewName.Items.Insert(0, "")

KSddlNewName2.DataSource = DSNewName
KSddlNewName2.DataTextField = "Expr4"
KSddlNewName2.DataValueField = "ZNumber"
KSddlNewName2.DataBind()
KSddlNewName2.Items.Insert(0, "")

'Make SQL Statement to populate the third ddl, KSddlNewRateType

End Sub
Public Sub buildKSddlNewP3ResourceCode()

KSddlNewP3ResourceCode.DataSource = DSNewP3ResCode
KSddlNewP3ResourceCode.DataTextField = "Expr1"
KSddlNewP3ResourceCode.DataValueField = "RES"
KSddlNewP3ResourceCode.DataBind()
KSddlNewP3ResourceCode.Items.Insert(0, "")
KSddlNewRateType.SelectedIndex = 1 'Select A for the Rate Typ

KSddlNewP3ResourceCode2.DataSource = DSNewP3ResCode
KSddlNewP3ResourceCode2.DataTextField = "Expr1"
KSddlNewP3ResourceCode2.DataValueField = "RES"
KSddlNewP3ResourceCode2.DataBind()
KSddlNewP3ResourceCode2.Items.Insert(0, "")
KSddlNewRateType2.SelectedIndex = 1 'Select A for the Rate Typ


End Sub


End Class
 
It may be easier to understand if you simply use one DDL, one DataSet and then try adding it to the cache and binding to the cached record (it would certainly make it easier to understand from our point of view as it will remove all the redundant code that is masking your problem.

However, fom just having a quick look it looks as though you are binding the DDL to a DataSet and not the cached version of it which is what I assume you were trying to do?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ca8msm,

Correct...I'm trying to build the KSddlNewName ddl from the cached dataset DSNewName
 
Got it by (see =>):

=>DSNewName = Cache("DSNewName")

KSddlNewName.DataSource = DSNewName
KSddlNewName.DataTextField = "Expr4"
KSddlNewName.DataValueField = "ZNumber"
KSddlNewName.DataBind()
KSddlNewName.Items.Insert(0, "")

KSddlNewName2.DataSource = DSNewName
KSddlNewName2.DataTextField = "Expr4"
KSddlNewName2.DataValueField = "ZNumber"
KSddlNewName2.DataBind()
KSddlNewName2.Items.Insert(0, "")


...and...




=>DSNewP3ResCode = Cache("DSNewP3ResCode")

KSddlNewP3ResourceCode.DataSource = DSNewP3ResCode
KSddlNewP3ResourceCode.DataTextField = "Expr1"
KSddlNewP3ResourceCode.DataValueField = "RES"
KSddlNewP3ResourceCode.DataBind()
KSddlNewP3ResourceCode.Items.Insert(0, "")
KSddlNewRateType.SelectedIndex = 1 'Select A for the Rate Typ

KSddlNewP3ResourceCode2.DataSource = DSNewP3ResCode
KSddlNewP3ResourceCode2.DataTextField = "Expr1"
KSddlNewP3ResourceCode2.DataValueField = "RES"
KSddlNewP3ResourceCode2.DataBind()
KSddlNewP3ResourceCode2.Items.Insert(0, "")
KSddlNewRateType2.SelectedIndex = 1 'Select A for the Rate Typ

...and the ddls are now working!

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top