473,378 Members | 1,416 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Dropdown List Value

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
3 2766
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two...
6
by: Mark | last post by:
I have two dropdown lists. Both have autopostback set to true. In both dropdowns, when you select an item from the list, it redirects to the Value property of the dropdown. Nothing fancy. ...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
5
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My...
0
by: Kay | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp...
0
by: Kay O'Keeffe | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp...
3
by: er1 | last post by:
Hi all, I have created a double dropdown list. Based on the first list selection, second list populates (this works fine). I have a submit button, which when clicked should run a select query...
6
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList...
4
by: Paul | last post by:
Hi all, I have a page that has a form on it which has a dropdown list on it. It connect to an sql database and populate the list. What I would like to do is make the list editable so that if the...
5
by: plumba | last post by:
Hi all. I have two drop down menus, the first a list of Departments, the second a list of Sections. Each Department has a set of Setions, so the Sections dropdown contains complete list of all...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.