By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,620 Members | 1,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,620 IT Pros & Developers. It's quick & easy.

Dropdown List Value

P: n/a
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
Oct 13 '08 #1
Share this Question
Share on Google+
3 Replies

P: n/a
It looks like you are rebinding your data on each postback so items are
cleared and the selected value is changed. You likely should use a "If Not
IsPostback" test to bind only if this is not a postback...

"John" <ri**********@hotmail.coma écrit dans le message de groupe de
discussion :
25**********************************...oglegroups.com...
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

Oct 13 '08 #2

P: n/a
On Oct 13, 9:55*am, "Patrice" <http://www.chez.com/scribe/wrote:
It looks like you are rebinding your data on each postback so items are
cleared and the selected value is changed. You likely should use a "If Not
IsPostback" test to bind only if this is not a postback...

"John" <riley_wri...@hotmail.coma écrit dans le message de groupe de
discussion :
25cadd16-e2bf-4405-b97d-e17c8b38b...@m74g2000hsh.googlegroups.com...
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- Hide quoted text -

- Show quoted text -
That did it. Thanks.

John
Oct 13 '08 #3

P: n/a
this requires viewstate be turned on. a better approach is to disable
viewstate and databind in oninit.

-- bruce (sqlwork.com)
"Patrice" wrote:
It looks like you are rebinding your data on each postback so items are
cleared and the selected value is changed. You likely should use a "If Not
IsPostback" test to bind only if this is not a postback...

"John" <ri**********@hotmail.coma crit dans le message de groupe de
discussion :
25**********************************...oglegroups.com...
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

Oct 13 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.