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