Solved

Three Tier Design for DropDownList with parameterized stored procedure

Posted on 2010-11-16
3
668 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:tis9700
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 34150491
I think you can have one method to which you supply the name or type of list to populate. The other option is to have a method for each of the lists in the business logic layer which then uses the single stored procedure to populate the list.
0
 

Author Comment

by:tis9700
ID: 34154481
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?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34154827
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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the most frequent problems a "newbie" developer may encounter is having to deal with different data formats. One for all: THE DATE We, as humans, need to "see" a date and then interpret it (much of the times this is an automatic operation)…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question