Avatar of tis9700
tis9700
 asked on

Three Tier Design for DropDownList with parameterized stored procedure

Good morning,

Currently I've been populating DropDownList in the code behind of web page. Opening the connection, using the command object to run the stored proc, and binding it to the DropDownList with a procedure and calling it in the page load event.

I could end up having 24 or more of these through out the site. So I think it's time for me to try using a Data Access Layer and Business Logic Layer.

What would be the best approach for the following code? It populates three DropDownList using the same stored procedure but with different parameter values.

I haven't found any examples out there as of yet.

Thanks MyCode.pdf
Visual Basic.NETASP.NETProgramming Theory

Avatar of undefined
Last Comment
Nasir Razzaq

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Nasir Razzaq

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
tis9700

ASKER
IHi Code Cruiser,

I'm not clear on what you're suggesting. Could you explain a little more.

Are you refering to List(Of Type)? And using it to store a list of my parameter values? I think I need to see a tutorial on this, do you know where I can find one?
Nasir Razzaq

No. By list, I meant dropdownlist. You can have a single method which accepts the name or type of list to populate. Here is an example

Public Function GetList(ListName As String) As DataTable
    If ListName = "City" Then
       ...
    ElseIf ListName = ...
    ...
    End If
End Function

CityList.Datasource = GetList("City")

Another option is to use an enum

Public Enum ListTypes
City
ContactType
...
End Enum

Public Function GetList(ListType as ListTypes) As DataTable
      If ListType = ListTypes.City Then
      ...
      End If
End Function

CityList.Datasource = GetList(ListTypes.City)


The third option is to have a separate function for each list so

Public Function GetCityList() As DataTable
End Function



Note: Where ever I used "...", it means that other code can go in there.
Your help has saved me hundreds of hours of internet surfing.
fblack61