Tidy up code

AllenJ

New member
Joined
Jun 5, 2006
Messages
2
Programming Experience
Beginner
Hi all,
I have 2 subroutine in my dataAccess class that basically populates dropdownbox and listbox.
I'm trying to cut this down to one instead of two, is it possible please?
Present code(s)
VB.NET:
Public Overloads Sub FillDBControl(ByVal lb As ListBox, ByVal sql As String, ByVal value As String, ByVal text As String)
lb.DataSource = ReturnDR(sql)
lb.DataTextField = text
lb.DataValueField = value
lb.DataBind()
End Sub
And the other
VB.NET:
Public Overloads Sub FillDBControl(ByVal ddl As DropDownList, ByVal sql As String, ByVal value As String, ByVal text As String)
ddl.DataSource = ReturnDR(sql)
ddl.DataTextField = text
ddl.DataValueField = value
ddl.DataBind()
End Sub
What i'd like is to have just the one like so..
Public Sub FillDBControl(c as control, sql as string .....)
Any possibilities..
ASP.Net 2.0
Thank you
Allen
 
Last edited by a moderator:
Yes, both DropDownList and ListBox will pass as type ListControl (which is the abstract base class they inherit from):
VB.NET:
Public Overloads Sub FillDBControl(ByVal c As [COLOR=darkgreen]ListControl[/COLOR], ByVal sql As String, ByVal value As String, ByVal text As String)
  c.DataSource = ReturnDR(sql)
  c.DataTextField = text
  c.DataValueField = value
  c.DataBind()
End Sub
 
Back
Top