473,386 Members | 1,758 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,386 software developers and data experts.

SelectedItem.Value

I want to update a database record with a number of fields - doesn't sound
to difficult at this stage!

I have a system to select the correct record from the database and load the
data into a form across a number of text boxes and a single drop down list
(the idea being that the text boxes can be edited and the drop down listed
altered to reflect a new value if necessary). The drop down list in the form
is loaded from the appropriate database table with the various options and
then set to the correct value to match the record.

daGroups.Fill(dsLocalInfo, "tblGroups")
ddlGroup.DataBind
ddlGroup.SelectedItem.Text = litGroup.Text
ddlGroup.Visible = True
txtName.Text = litName.Text
txtDescription.Text = litName.Text
etc etc etc

I then use an update command to update the record in the database

cmdUpdateLocalInfo.Parameters("GroupID").Value = ddlGroup.SelectedItem.Value
cmdUpdateLocalInfo.Parameters("Name").Value = txtName.Text
etc etc

The bit I don't understand is that if I call the update without having first
used the drop down list control the update succeeds but updates the GroupID
to be the value which naturally would be at the top of the list if I hadn't
set it in the earlier statement (i.e. ddlGroup.SelectedItem.Text =
litGroup.Text). Where as if I call the update after having changed the
selection on the drop down list control the update works and accepts the
correct value from the drop down list control. Almost as if the selected
item has to be selected for it to register, where as I have selected in the
code previously (i.e. most records wont require changing groups on the drop
down list).

Hopefully this might ring a bell with somebody as I have done this (or
similar) many times before but cant work out what is wrong here!

Martyn Fewtrell
mf*******@networkclub.co.uk


Nov 19 '05 #1
4 2082
Are you checking that the page has not been posted back before selecting the
DDL item?

"Martyn Fewtrell" wrote:
I want to update a database record with a number of fields - doesn't sound
to difficult at this stage!

I have a system to select the correct record from the database and load the
data into a form across a number of text boxes and a single drop down list
(the idea being that the text boxes can be edited and the drop down listed
altered to reflect a new value if necessary). The drop down list in the form
is loaded from the appropriate database table with the various options and
then set to the correct value to match the record.

daGroups.Fill(dsLocalInfo, "tblGroups")
ddlGroup.DataBind
ddlGroup.SelectedItem.Text = litGroup.Text
ddlGroup.Visible = True
txtName.Text = litName.Text
txtDescription.Text = litName.Text
etc etc etc

I then use an update command to update the record in the database

cmdUpdateLocalInfo.Parameters("GroupID").Value = ddlGroup.SelectedItem.Value
cmdUpdateLocalInfo.Parameters("Name").Value = txtName.Text
etc etc

The bit I don't understand is that if I call the update without having first
used the drop down list control the update succeeds but updates the GroupID
to be the value which naturally would be at the top of the list if I hadn't
set it in the earlier statement (i.e. ddlGroup.SelectedItem.Text =
litGroup.Text). Where as if I call the update after having changed the
selection on the drop down list control the update works and accepts the
correct value from the drop down list control. Almost as if the selected
item has to be selected for it to register, where as I have selected in the
code previously (i.e. most records wont require changing groups on the drop
down list).

Hopefully this might ring a bell with somebody as I have done this (or
similar) many times before but cant work out what is wrong here!

Martyn Fewtrell
mf*******@networkclub.co.uk


Nov 19 '05 #2
Thanks Saleek but I'm not quite sure where you are coming from with that
one.

When the page originally loads, the record is displayed using literals and
then the user has the option to Delete the Record, Update the Record etc. If
the user selects the Update option the page posts back, the values from the
literal are loaded into the text boxes and the drop down list, visibility is
turned off on the literals and on for the text boxes and the drop down list.
The value for the drop down list is set to the correct value for that
record.

The user can then change any of the values before calling the Update routine
with another button.

The drop down list isn't loaded with any data until the user elect to Update
the record.

What are you thinking?

Martyn Fewtrell
mf*******@networkclub.co.uk
"saleek" <sa****@discussions.microsoft.com> wrote in message
news:A7**********************************@microsof t.com...
Are you checking that the page has not been posted back before selecting
the
DDL item?

"Martyn Fewtrell" wrote:
I want to update a database record with a number of fields - doesn't
sound
to difficult at this stage!

I have a system to select the correct record from the database and load
the
data into a form across a number of text boxes and a single drop down
list
(the idea being that the text boxes can be edited and the drop down
listed
altered to reflect a new value if necessary). The drop down list in the
form
is loaded from the appropriate database table with the various options
and
then set to the correct value to match the record.

daGroups.Fill(dsLocalInfo, "tblGroups")
ddlGroup.DataBind
ddlGroup.SelectedItem.Text = litGroup.Text
ddlGroup.Visible = True
txtName.Text = litName.Text
txtDescription.Text = litName.Text
etc etc etc

I then use an update command to update the record in the database

cmdUpdateLocalInfo.Parameters("GroupID").Value =
ddlGroup.SelectedItem.Value
cmdUpdateLocalInfo.Parameters("Name").Value = txtName.Text
etc etc

The bit I don't understand is that if I call the update without having
first
used the drop down list control the update succeeds but updates the
GroupID
to be the value which naturally would be at the top of the list if I
hadn't
set it in the earlier statement (i.e. ddlGroup.SelectedItem.Text =
litGroup.Text). Where as if I call the update after having changed the
selection on the drop down list control the update works and accepts the
correct value from the drop down list control. Almost as if the selected
item has to be selected for it to register, where as I have selected in
the
code previously (i.e. most records wont require changing groups on the
drop
down list).

Hopefully this might ring a bell with somebody as I have done this (or
similar) many times before but cant work out what is wrong here!

Martyn Fewtrell
mf*******@networkclub.co.uk


Nov 19 '05 #3
Okay, that rules out what I was thinking. And you have viewstate turned on
for the DDL yes?

I would edit out your execution of the query and output the DDL value to a
label on potsback to check which values are being selected.

"Martyn Fewtrell" wrote:
Thanks Saleek but I'm not quite sure where you are coming from with that
one.

When the page originally loads, the record is displayed using literals and
then the user has the option to Delete the Record, Update the Record etc. If
the user selects the Update option the page posts back, the values from the
literal are loaded into the text boxes and the drop down list, visibility is
turned off on the literals and on for the text boxes and the drop down list.
The value for the drop down list is set to the correct value for that
record.

The user can then change any of the values before calling the Update routine
with another button.

The drop down list isn't loaded with any data until the user elect to Update
the record.

What are you thinking?

Martyn Fewtrell
mf*******@networkclub.co.uk
"saleek" <sa****@discussions.microsoft.com> wrote in message
news:A7**********************************@microsof t.com...
Are you checking that the page has not been posted back before selecting
the
DDL item?

"Martyn Fewtrell" wrote:
I want to update a database record with a number of fields - doesn't
sound
to difficult at this stage!

I have a system to select the correct record from the database and load
the
data into a form across a number of text boxes and a single drop down
list
(the idea being that the text boxes can be edited and the drop down
listed
altered to reflect a new value if necessary). The drop down list in the
form
is loaded from the appropriate database table with the various options
and
then set to the correct value to match the record.

daGroups.Fill(dsLocalInfo, "tblGroups")
ddlGroup.DataBind
ddlGroup.SelectedItem.Text = litGroup.Text
ddlGroup.Visible = True
txtName.Text = litName.Text
txtDescription.Text = litName.Text
etc etc etc

I then use an update command to update the record in the database

cmdUpdateLocalInfo.Parameters("GroupID").Value =
ddlGroup.SelectedItem.Value
cmdUpdateLocalInfo.Parameters("Name").Value = txtName.Text
etc etc

The bit I don't understand is that if I call the update without having
first
used the drop down list control the update succeeds but updates the
GroupID
to be the value which naturally would be at the top of the list if I
hadn't
set it in the earlier statement (i.e. ddlGroup.SelectedItem.Text =
litGroup.Text). Where as if I call the update after having changed the
selection on the drop down list control the update works and accepts the
correct value from the drop down list control. Almost as if the selected
item has to be selected for it to register, where as I have selected in
the
code previously (i.e. most records wont require changing groups on the
drop
down list).

Hopefully this might ring a bell with somebody as I have done this (or
similar) many times before but cant work out what is wrong here!

Martyn Fewtrell
mf*******@networkclub.co.uk



Nov 19 '05 #4
I've worked it out and as usual its human error!!!!

ddlGroup.SelectedItem.Text = litGroup.Text - changes the value of the text
on the SelectedItem rather than Selecting the item to the required text
value.

I now use ddlGroup.SelectedValue = Session("GroupID") - where
Session("GroupID") holds the value of the GroupID.

This sets the drop down list correctly and therefore saves the correct value
during the update!

Thanks anyway

Martyn Fewtrell
mf*******@networkclub.co.uk

"saleek" <sa****@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...
Okay, that rules out what I was thinking. And you have viewstate turned on
for the DDL yes?

I would edit out your execution of the query and output the DDL value to a
label on potsback to check which values are being selected.

"Martyn Fewtrell" wrote:
Thanks Saleek but I'm not quite sure where you are coming from with that
one.

When the page originally loads, the record is displayed using literals
and
then the user has the option to Delete the Record, Update the Record etc.
If
the user selects the Update option the page posts back, the values from
the
literal are loaded into the text boxes and the drop down list, visibility
is
turned off on the literals and on for the text boxes and the drop down
list.
The value for the drop down list is set to the correct value for that
record.

The user can then change any of the values before calling the Update
routine
with another button.

The drop down list isn't loaded with any data until the user elect to
Update
the record.

What are you thinking?

Martyn Fewtrell
mf*******@networkclub.co.uk
"saleek" <sa****@discussions.microsoft.com> wrote in message
news:A7**********************************@microsof t.com...
> Are you checking that the page has not been posted back before
> selecting
> the
> DDL item?
>
> "Martyn Fewtrell" wrote:
>
>> I want to update a database record with a number of fields - doesn't
>> sound
>> to difficult at this stage!
>>
>> I have a system to select the correct record from the database and
>> load
>> the
>> data into a form across a number of text boxes and a single drop down
>> list
>> (the idea being that the text boxes can be edited and the drop down
>> listed
>> altered to reflect a new value if necessary). The drop down list in
>> the
>> form
>> is loaded from the appropriate database table with the various options
>> and
>> then set to the correct value to match the record.
>>
>> daGroups.Fill(dsLocalInfo, "tblGroups")
>> ddlGroup.DataBind
>> ddlGroup.SelectedItem.Text = litGroup.Text
>> ddlGroup.Visible = True
>> txtName.Text = litName.Text
>> txtDescription.Text = litName.Text
>> etc etc etc
>>
>> I then use an update command to update the record in the database
>>
>> cmdUpdateLocalInfo.Parameters("GroupID").Value =
>> ddlGroup.SelectedItem.Value
>> cmdUpdateLocalInfo.Parameters("Name").Value = txtName.Text
>> etc etc
>>
>> The bit I don't understand is that if I call the update without having
>> first
>> used the drop down list control the update succeeds but updates the
>> GroupID
>> to be the value which naturally would be at the top of the list if I
>> hadn't
>> set it in the earlier statement (i.e. ddlGroup.SelectedItem.Text =
>> litGroup.Text). Where as if I call the update after having changed the
>> selection on the drop down list control the update works and accepts
>> the
>> correct value from the drop down list control. Almost as if the
>> selected
>> item has to be selected for it to register, where as I have selected
>> in
>> the
>> code previously (i.e. most records wont require changing groups on the
>> drop
>> down list).
>>
>> Hopefully this might ring a bell with somebody as I have done this (or
>> similar) many times before but cant work out what is wrong here!
>>
>> Martyn Fewtrell
>> mf*******@networkclub.co.uk
>>
>>
>>
>>
>>


Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: gordon | last post by:
Hi I have a combo box that my application uses to select an item for a regression function. I would like to convert the selected item to a string value and use this value later in my code. ...
0
by: huobazi | last post by:
I have many dropdownlist controls in my ascx (and use LoadControl in a aspx fiel) file,so i write a method "InitList(DropDownList list,string strsql,string TextField,string ValueField)" but when i...
4
by: Ivan | last post by:
Hi, I have a problem with a page which has about 50 web controls , 12 of the are DropDownList. Also, I have a "Continue" button, and on the server code an event sub btnContinue_Click, where I...
6
by: Julius Fenata | last post by:
Dear all, I have created client-side scripting to trigger event onChange from code-behind, like this: DropDownList1.Attributes = "GenerateArticleID()"; At the script on Windows Form, I...
4
by: darrel | last post by:
what is the difference between these? I always end up typing 'selectedvalue' only to have problems and then realize I meant to use selecteditem.value (the value of the selected item). When would...
2
by: Antonio D'Ottavio | last post by:
Good morning, I've a problem with a dropdownlist located inside any row of a datalist, I fill both datalist and dropdownlist at runtime, the problem is with the dropdownlist infact using the event...
8
by: Raoul Watson | last post by:
Is there a way to simulate a selection (let's say to the third item on the list) and cause the highlight to appear? Any ideas welcomed and appreciated. Thanks!
1
by: RSH | last post by:
Hi, I am experimenting with the Viewstate and based on a few articles I have read, I put together a test. it is a simple test where I am dynamically creating a DropDownList that contains 25000...
2
by: Tracey | last post by:
How can I convert to a string (what I thought was a string)? and/or How can I assign the value of a selected item in a list box to Label1.Text? using VB in VS2005. Thanks, Tracey I completed...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.