_Esam
asked on
Populate a drop down list (with two data columns)? VB.NET
Hi,
.
I looked at some resoureces before asking the question....but couldn't do it ...so asking ....
I need to populate a ddl from a database...
"I would like to show two columns from a database to the ddl"
????????IS IT POSSIBLE?????????????
My my code below so far attempted to populate the ddl with just one column..
let me know how i can make it to show two columms from the database...
Here is what I tried:
My ddl is:
<asp:DropDownList id="coursesddl" Runat="server"></asp:DropD ownList>
My ddl databing code:
Dim ccddl As New OleDbConnection
Dim sddl As String = Server.MapPath("UST.mdb")
ccddl.ConnectionString = "provider =Microsoft.Jet.OLEDB.4.0; data source = " + sddl
ccddl.Open()
Dim daddl As New OleDbDataAdapter("SELECT COURSE_ID FROM COURSES ", ccddl)
Dim dsddl As New DataSet
daddl.Fill(dsddl, "COURSES")
coursesddl.DataSource = dsddl.Tables("COURSES").De faultView
coursesddl.DataTextField = "COURSE_ID"
coursesddl.DataValueField = "COURSE_ID"
coursesddl.DataBind()
ccddl.Close()
Thanks..
_Esam
.
I looked at some resoureces before asking the question....but couldn't do it ...so asking ....
I need to populate a ddl from a database...
"I would like to show two columns from a database to the ddl"
????????IS IT POSSIBLE?????????????
My my code below so far attempted to populate the ddl with just one column..
let me know how i can make it to show two columms from the database...
Here is what I tried:
My ddl is:
<asp:DropDownList id="coursesddl" Runat="server"></asp:DropD
My ddl databing code:
Dim ccddl As New OleDbConnection
Dim sddl As String = Server.MapPath("UST.mdb")
ccddl.ConnectionString = "provider =Microsoft.Jet.OLEDB.4.0; data source = " + sddl
ccddl.Open()
Dim daddl As New OleDbDataAdapter("SELECT COURSE_ID FROM COURSES ", ccddl)
Dim dsddl As New DataSet
daddl.Fill(dsddl, "COURSES")
coursesddl.DataSource = dsddl.Tables("COURSES").De
coursesddl.DataTextField = "COURSE_ID"
coursesddl.DataValueField = "COURSE_ID"
coursesddl.DataBind()
ccddl.Close()
Thanks..
_Esam
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i had some problem earlier to get the right results due to some property error for this part > daddl.Fill(dsddl, "COURSES") .
it's working fine now except that when i concaneted two columns, the result somehow looks not so attractive...
like:
CS510 - This is course A
CS525T - This is course B with a T
CS625 - This is course C with no T.
Would have been nice if all the "This" were aligned nicely, vertically ||||
Let me know if you might have any suggestion on this (any way around)..
Thanks.
_Esam
it's working fine now except that when i concaneted two columns, the result somehow looks not so attractive...
like:
CS510 - This is course A
CS525T - This is course B with a T
CS625 - This is course C with no T.
Would have been nice if all the "This" were aligned nicely, vertically ||||
Let me know if you might have any suggestion on this (any way around)..
Thanks.
_Esam
what is the max length for the course id? assuming it is 6
use this query
SELECT COURSE_ID,
left(convert(varchar(6), COURSE_ID) + ' ', 6) + ' - ' + course_Name as Course_Name FROM COURSES
the number spaces in the
left(convert(varchar(6), COURSE_ID) + ' ', 6)
statement = 6 i.e. the max digits of the course id ...
with this statement the data will look like
CS510 - This is course A
CS525T- This is course B with a T
CS625 - This is course C with no T.
use this query
SELECT COURSE_ID,
left(convert(varchar(6), COURSE_ID) + ' ', 6) + ' - ' + course_Name as Course_Name FROM COURSES
the number spaces in the
left(convert(varchar(6), COURSE_ID) + ' ', 6)
statement = 6 i.e. the max digits of the course id ...
with this statement the data will look like
CS510 - This is course A
CS525T- This is course B with a T
CS625 - This is course C with no T.
SELECT COURSE_ID, COURSE_ID + ' - ' + course_Name as Course_Name FROM COURSES