Figuring out why a dropdownlist is considered empty

P

Plateriot

Is there a more error proof way of deciding when to try:

Dim li As ListItem
li = Me.cmbSPEC.Items.FindByValue(Session("ssSpec"))

If li IsNot Nothing Then
li.Selected = True
end if


I figured out that I was receiving the error because my dropdown list was
empty
But now on this particular non-working instance, I have appropriately filled
my dropdown list manually in several pages including the one
I want it to work on... like this:


Private Sub FillSpecs()
With Me.cmbSPEC
.DataSource = Vitals_TB.PullSpecialties
.DataTextField = "Specialty"
.DataValueField = "DeptSpecID"

.DataBind()
End With

End Sub


Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

If Not IsPostBack Then
PI = GetLoginData()
WP = GetWorkingProvider(Session("ssWorkingProvID"))


strNUID = PI.strNUID
SecLevel = PI.strSecLevel
Session("ssNUID") = strNUID

FillSpecs()



Dim li As ListItem
li = Me.cmbSPEC.Items.FindByValue(Session("ssSpec"))


If li IsNot Nothing Then
li.Selected = True
Else
'Start the Spec with the providers spec/dept
Session.Add("ssSpec", WP.strProvDept)

'Figure out why this line is throwing a null exception

Me.cmbSPEC.Items.FindByValue(Session("ssSpec")).Selected =
True
'I've mannually filled the combobox...
'I've checked the session variable, both are good -- so why
is it still throwing a null exception?

Me.Label1.Text = Session("ssSpec")
End If
End If

End Sub

it's strange because I have the same exact code on another page, but for
some reason its not working on this page -- what else can I examin to get to
the bottom of this?

Any reasonable suggestions would be greatly appreciated
 
C

cfps.Christian

You might have to put the combo's loading logic within Form_Init or
Form_LoadComplete. If you search the group for something like "Combo
forgetting values" you'll find where I got the idea from.
 
P

Plateriot

I tried exactly that - but I still get the same error.

I also tried finding the post using 'Combo forgetting values' or 'Forgetting
values' + Combo box - and the closest article I could find was 'Dynamic
Control Creation' betwee Philip and Sameer.

Sure, putting the combo's loading logic may work in a different event, but
explain why it works normally when I use the same exact logic on another page
that is exactly the same, with the exception of the combo box's name.

I've experienced a lot of this with Microsoft. Controls "forgetting" their
values... as if you have to 'Wake' them up to make them remember.

My MainFrame friend always laughs when he finds things that have a life of
their own in Visual Studio.
 

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

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top