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'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.
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?