Drop Down List Problem :D

Leo1983

New member
Joined
Mar 17, 2009
Messages
1
Programming Experience
5-10
Hi, I have a drop down list with multiple choices. When I made a selection and went to the next page that selection won't show the wording, only show the number correlates to the choice I made (e.g. I chose option no 1 (Animal), the drop down list on the next page will only show 1 instead of Animal). I'm using a three-tier design in VS 2005 with mysql.


1st Page coding:
Dim Department = dd_Department.SelectedValue

dd_Department.SelectedValue = Session("Department") -> mysql database

Dim pop_nat As Data.DataSet = business.populate_Department()
dd_Department.DataSource = pop_nat
dd_Department.DataValueField = "DeptID"
dd_Department.DataTextField = "DeptName"
dd_Department.DataBind()

2nd page coding:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ds As Data.DataSet

dd_Department.Text = ds.Tables(0).Rows(0)("DeptID")

Dim pop_nat As Data.DataSet = business.populate_Department()
dd_Department.DataSource = pop_nat
dd_Department.DataValueField = "DeptID"
dd_Department.DataTextField = "DeptName"
dd_Department.DataBind()

End Sub

should I use the toString() command or what?

Please help, thanks.
 
should I use the toString() command or what?

Start by clarifying your question in a manner we can understand. Also step through your code line by line and see the order you are trying to accomplish things.
VB.NET:
[COLOR="SeaGreen"]
'01) 
'    What datatype is department?
'
'    The SelectedValue method will return an object of the data in the 
'    ValueMember property; in this case what is later used to store the 
'    DepartmentId values so you also must convert this to a number datatype.
'
'    Being how you havent yet filled this control with any data and no 
'    items are yet selected Deparment will remain nothing
'
'    And although a value is attempted to be stored in Department (failed), 
'    it isnt used anywhere else in this code.[/COLOR]
Dim Department = dd_Department.SelectedValue

[COLOR="seagreen"]
'02)
'    You are now attempting to set a new value for the valuemember item 
'    instead of selecting a item again all in a control with no items.[/COLOR]
dd_Department.SelectedValue = Session("Department") -> mysql database

[COLOR="seagreen"]
'03)
'    A new dataset is created and now the control gets data bound to it[/COLOR]
Dim pop_nat As Data.DataSet = business.populate_Department()
dd_Department.DataSource = pop_nat
dd_Department.DataValueField = "DeptID"
dd_Department.DataTextField = "DeptName"
dd_Department.DataBind()

2nd page coding:
Protected Sub Page_Load() Handles Me.Load
[COLOR="seagreen"]
'04)
'      A new dataset is created[/COLOR]
Dim ds As Data.DataSet

[COLOR="seagreen"]
'05) 
'    ds is a new untyped dataset with no tables,  no columns and no data in it.
'
'    You then try to call the first table in ds (it has no tables)
'    The first record in this table (it has no data rows)
'
'    Keep in mind no matter what item was selected by the user
'    it doesnt matter your always attempting to get the DepartmentId
'    of the first Department record in the table
'    
'    Get the object value of column "DeptId" (is has no colums)
'    and assigns that objects (not a text value) to the text property
'    of dd_Department.text
'
'    At this point I dont know where the control dd_department is even 
'    located. If this is yet a new control on Form2 with the same name as
'    previously it then also hasnt been filled yet and contains no data
'[/COLOR]
dd_Department.Text = ds.Tables(0).Rows(0)("DeptID")

[COLOR="seagreen"]'06) 
'    A third dataset is then created and is now bound to dd_Deparment.[/COLOR]
Dim pop_nat As Data.DataSet = business.populate_Department()
dd_Department.DataSource = pop_nat
dd_Department.DataValueField = "DeptID"
dd_Department.DataTextField = "DeptName"
dd_Department.DataBind()

End Sub
 
Back
Top