J
John
I have two dropdown lists that I have bound to a datatable and set the
DataTextField and DataValueField for. Both lists show the values I
expect from the database. However, when I need to access the
valueField for a dropdown list I always get the first value. Here is
my code I do on load to bind the dropdowns:
Try
'load the Division Dropdown
dtDiv = objDAL.ExecuteDataTable("GetDivision")
With ddDivision
.DataSource = dtDiv
.DataTextField = "DivisionName"
.DataValueField = "DivisionID"
.DataBind()
End With
If dtDiv.Rows.Count = 1 Then 'load the dropdown of sites
automatically otherwise wait for the selection
objParam.CreateParameter("DivID",
dtDiv.Rows(0).Item(0).ToString, DbType.Int32,
ParameterDirection.Input)
dtSite = objDAL.ExecuteDataTable("GetPlant", objParam)
With ddPlant
.DataSource = dtSite
.DataTextField = "PlantName"
.DataValueField = "PlantID"
.DataBind()
End With
End If
Again, this loads just fine. I have a button on the form that does a
redirect based on the values selected:
Response.Redirect("Default.aspx?DivID=" & ddDivision.SelectedValue &
"&PlantID=" & ddPlant.SelectedValue)
However the ddPlant.SelectedValue is always 1 (the first value in the
list) regardless of which value I select in the dropdown. In the
SelectedIndexChanged field of the dropdown I tried to set a session
variable but this event never fires. Anyone have any idea how to get
the selected values of dropdown lists?
Thanks.
John
DataTextField and DataValueField for. Both lists show the values I
expect from the database. However, when I need to access the
valueField for a dropdown list I always get the first value. Here is
my code I do on load to bind the dropdowns:
Try
'load the Division Dropdown
dtDiv = objDAL.ExecuteDataTable("GetDivision")
With ddDivision
.DataSource = dtDiv
.DataTextField = "DivisionName"
.DataValueField = "DivisionID"
.DataBind()
End With
If dtDiv.Rows.Count = 1 Then 'load the dropdown of sites
automatically otherwise wait for the selection
objParam.CreateParameter("DivID",
dtDiv.Rows(0).Item(0).ToString, DbType.Int32,
ParameterDirection.Input)
dtSite = objDAL.ExecuteDataTable("GetPlant", objParam)
With ddPlant
.DataSource = dtSite
.DataTextField = "PlantName"
.DataValueField = "PlantID"
.DataBind()
End With
End If
Again, this loads just fine. I have a button on the form that does a
redirect based on the values selected:
Response.Redirect("Default.aspx?DivID=" & ddDivision.SelectedValue &
"&PlantID=" & ddPlant.SelectedValue)
However the ddPlant.SelectedValue is always 1 (the first value in the
list) regardless of which value I select in the dropdown. In the
SelectedIndexChanged field of the dropdown I tried to set a session
variable but this event never fires. Anyone have any idea how to get
the selected values of dropdown lists?
Thanks.
John