Property Accessor Function Problem?

L

Leon

Why this code is not working? I think the problem is in the business class
code.

****My Business Class------------
' Private variables
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
Private Shared myStateID As String

Public Shared Function GetSchoolByState(ByVal StateID As String) As DataSet
myStateID = StateID
Dim tool As New StuLotto.Accounts.Data.AccountsTool
Return tool.GetSchoolByStateList(myStateID)
End Function

' Properties
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
Public Property StateID() As String
Get
Return myStateID
End Get
Set(ByVal value As String)
myStateID = value
End Set
End Property


****My CodeBehind Class----------------
' Bind the school by selected state drop-down combobox
Private Sub SStateDDL_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SStateDDL.SelectedIndexChanged
Dim Schools As New DataSet
Dim Value As String = SStateDDL.SelectedItem.Value
Schools = Accounts.Business.AccountsTool.GetSchoolByState(Value)
SNameDDL.DataSource = Schools
SNameDDL.DataTextField = "SchoolName"
SNameDDL.DataValueField = "SchoolID"
SNameDDL.DataBind()
End Sub
 
L

Leon

when I select a state from the dropdownlist, the school dropdownlist suppose
to fill with school names, but somehow the state value is not getting back
to the business class. I think it's the way I'm using property get and set
accessor function.
 
G

Guest

Leon, it's still hard to tell from these snippets, but a couple things for
sure:

a) myStateID should not be a "shared" variable, because it's going to be
shared across all instances of that class (i.e. all users), which I doubt is
what you want. It also might be messing you up in this case because you set
that same value in both the set accessor and then again in GetSchoolsByState,
so that would be one good reason why you'd "lose" that value. The point of
having get/set is that you are controlling access to that value, so nobody
outside of get/set should be touching that private variable (i.e. use the
public StateID() property, not the private myStateID).

b) If GetSchoolByState is a shared function, which might make sense here,
why do you define a new instance of the tool class? A shared function is
always "there", so you'd just need to do tool.GetSchoolByState without the
need for the dim (although this isn't the problem in your case, it's just a
little odd).

hth,

Bill

P.S. Give people a chance to respond to your first post before you post a
*second*:)
 
L

Leon

I got it! Thanks for all the help!!!!
Bill Borg said:
Leon, it's still hard to tell from these snippets, but a couple things for
sure:

a) myStateID should not be a "shared" variable, because it's going to be
shared across all instances of that class (i.e. all users), which I doubt
is
what you want. It also might be messing you up in this case because you
set
that same value in both the set accessor and then again in
GetSchoolsByState,
so that would be one good reason why you'd "lose" that value. The point of
having get/set is that you are controlling access to that value, so nobody
outside of get/set should be touching that private variable (i.e. use the
public StateID() property, not the private myStateID).

b) If GetSchoolByState is a shared function, which might make sense here,
why do you define a new instance of the tool class? A shared function is
always "there", so you'd just need to do tool.GetSchoolByState without the
need for the dim (although this isn't the problem in your case, it's just
a
little odd).

hth,

Bill

P.S. Give people a chance to respond to your first post before you post a
*second*:)
 

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

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top