lz7cjc
asked on
retrieving the value from a drop down list
Hi
i am populating a drop down list on my web page from a database like this:
mySelect.Datasource = Ds1.tables("company")
...
...
<asp:DropDownList id="mySelect" datavaluefield="companyid" datatextfield="companyname " runat="server"/>
I want to retrieve the value that is chosen in this dropdown list and write it, along with other values from the web form... to the database
I currently have this line of code todo this:
...
Row.Item("companyID") = mySelect.selecteditem.valu e
...
However when i hit the submit button, rather than writing the value i have selected it writes the first value in the dropdown list...
Please could you tell me what i should be doing to get the value i select on the page to write to the DB rather than the first in the list
thanks
i am populating a drop down list on my web page from a database like this:
mySelect.Datasource = Ds1.tables("company")
...
...
<asp:DropDownList id="mySelect" datavaluefield="companyid"
I want to retrieve the value that is chosen in this dropdown list and write it, along with other values from the web form... to the database
I currently have this line of code todo this:
...
Row.Item("companyID") = mySelect.selecteditem.valu
...
However when i hit the submit button, rather than writing the value i have selected it writes the first value in the dropdown list...
Please could you tell me what i should be doing to get the value i select on the page to write to the DB rather than the first in the list
thanks
ASKER
i thought i had done that
the html code appears as i would hope:
<select name="mySelect" id="mySelect">
<option value="1">Huxley Associates</option>
<option value="2">HW Group</option>
<option value="3">Computer Futures</option>
<option value="4">Inside-Solutions </option>
<option value="5">Abraxas</option>
<option value="6">Full Circle</option>
<option value="7">Progressive</opt ion>
<option value="8">Microcom Ltd </option>
<option value="9">Orbis Resourcing Ltd </option>
<option value="10">Siena Red </option>
<option value="11">Ideal People </option>
<option value="12">ICAD Technology</option>
<option value="13">Informatiq Consulting </option>
<option value="14">Timothy James Consulting</option>
</select>
i.e the text and value fields are appearing on the page as i would hope... it is when i hit submit that
Row.Item("companyID") = mySelect.selecteditem.valu e
takes the first value in the dropdown list rather than the one selected in the form
the html code appears as i would hope:
<select name="mySelect" id="mySelect">
<option value="1">Huxley Associates</option>
<option value="2">HW Group</option>
<option value="3">Computer Futures</option>
<option value="4">Inside-Solutions
<option value="5">Abraxas</option>
<option value="6">Full Circle</option>
<option value="7">Progressive</opt
<option value="8">Microcom Ltd </option>
<option value="9">Orbis Resourcing Ltd </option>
<option value="10">Siena Red </option>
<option value="11">Ideal People </option>
<option value="12">ICAD Technology</option>
<option value="13">Informatiq Consulting </option>
<option value="14">Timothy James Consulting</option>
</select>
i.e the text and value fields are appearing on the page as i would hope... it is when i hit submit that
Row.Item("companyID") = mySelect.selecteditem.valu
takes the first value in the dropdown list rather than the one selected in the form
have you tried: Row.Item("companyID") = mySelect.selectedvalue
without the .value at the end?
without the .value at the end?
ASKER
just tried that and got an error as it seems to be taking the textfield value
"Couldn't store <Progressive> in consultantID Column. Expected type is Int32."
bennet is the display value... i want the value associated with bennett ... in this case 7 since the DB is expecting an integer not a string
thanks for the idea though
"Couldn't store <Progressive> in consultantID Column. Expected type is Int32."
bennet is the display value... i want the value associated with bennett ... in this case 7 since the DB is expecting an integer not a string
thanks for the idea though
ASKER
i think the issue has something to do with the point at which the code is asking for the value ... by the time it assigns the value from the DDL to the DB the page has reloaded and the DDL has already been reset and the default (first) value in the list is entered into the db
this is my guess as to what is happening... but then again what do i know
thanks
this is my guess as to what is happening... but then again what do i know
thanks
Does the data rebind itself during postback?
ASKER
is that a rhetorical question?
not sure - what would i need to do to ensure it does/doesn't
thanks
not sure - what would i need to do to ensure it does/doesn't
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you ... that worked a treat
ddlCompName.DataSource = dsTemp '<--- (Dataset Name)
ddlCompName.DataMember = "Results" '<--- (Table Name)
ddlCompName.DataTextField = "Comp_Name" '<--- (Column Name)
ddlCompName.DataValueField