![]() |
| |||||||
![]() | « Previous Thread | Next Thread » |
| | LinkBack | Thread Tools | Display Modes |
| Sponsored Links |
| ||||
| It's not something I've done, but I see no reason why you couldn't, you just need to set it as a type that can populate a dropdown. To populate a dropdownlist in code behind, I'd have something like this:- Code: sub build_ddl_myddl()
Dim conn as new mysqlconnection(connString)
Dim mycommand as new mysqlcommand("SELECT fld_id,fld_text FROM tbl_name")
mycommand.connection = conn
Dim rs as mysqldatareader
try
conn.open
rs = mycommand.executereader
if rs.hasrows then
my_ddlid.datasource = rs
my_ddlid.datavaluefield = "fld_id"
my_ddlid.datatextfield = "fld_text"
my_ddlid.databind()
end if
rs.close
catch ex as exception
response.write(ex.message.tostring)
finally
mycommand.dispose
conn.close
end try
end sub
Code: my_ddlid = myBLL.getdropdown I suspect J will have a better way of doing it, but in theory what you're trying to do should be no problem. It's just a matter of what you return the data form you function as to manipulate it into a DDL. |
| ||||
![]() Let's say you wanted to populate your dropdown with a list of users in the system. You already have the users class with the appropriate objects. What you can do is create a new class that is a collection, or List Of the User class: Code: Namespace Company.AppName.BO
Inherits List(Of User)
Public Class UserList
Public Sub New()
End Sub
End Class
End Namespace
Now, you can take a function that gets the data to populate this list and return the UserList to bind to the dropdown. So, in the BLL, you'll have this function: GetUserList() As UserList In the DAL, the same thing: GetUserList() As UserList Then just bind it to the DropDown ![]() For example of the list, see here: Building Layered Web Applications with Microsoft ASP.NET 2.0 - Part 1 - Imar.Spaanjaars.Com Download the sample file and check the "App_Code\BusinessObject\Collections" folder.
__________________ jmurrayhead Did I help you out? Make me popular by clicking the icon!If you found a post helpful, please click the button in the lower right-hand corner of the post.Powered by ASP.Net |
| ||||
| J How would you then create a dropdown that, for example, used a primary key field as the option value and firstname & " " & surname as the text? Just to give me some pointers... Thanks |
| ||||
| Because you're using the object as a datasource, you would then set those values to the equivalent properties of the class. You might want to make an additional property "FullName" that returns the concatenated values of FirstName and Surname and set that as the text. |
| The Following User Says Thank You to jmurrayhead For This Useful Post: | ||
richyrich (May 27th, 2008) | ||
| ||||
| RR; There are no less than 8 ways to bind a DDL (so I've read). If you are wanting to bind to the results of a query in a data table then: Code: Dim sql As String = "SELECT id, firstname || ' ' || surname as fullName from aTable" Dim da As New SqlDataAdapter(sql, "data source=.;initial catalog=myDB;user id=sa") Dim dt As New DataTable da.Fill(dt) da.Dispose() Me.DropDownList1.DataSource = dt Me.DropDownList1.DataTextField = "fullName" Me.DropDownList1.DataValueField = "id" Me.DropDownList1.DataBind() Note that || is the concat for Oracle, your SQL may differ.
__________________ Wolffy ------------------------ Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary. |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dynamic dropdown list with multiple records | Rebelle | ASP Development | 4 | April 30th, 2008 05:33 AM |
| Using Dropdown List Value in Database SQL Query | richyrich | Classic ASP | 0 | April 2nd, 2008 10:05 AM |
| Creating Dynamic Dropdown Menu!? | jarvelous | ASP Development | 1 | March 20th, 2008 12:30 PM |
| Sponsored Links |
| ASP.NET Resource Index a directory of ASP.NET tutorials, applications, scripts, assemblies and articles for the novice to professional developer. Free Web Directory Including Chats and Forums Resources, Offer automatic, instant and free directory submissions. | URLZ Web Directory URLZ Web Directory Free Web Directory - Add Your Link The Little Web Directory | Free Web Directory Pegasus free web directory is a free directory organised by categories. Web Directory & SEO Services dirroot web directory |