Last post Nov 04, 2011 08:29 PM by b471code3
Nov 04, 2011 06:28 PM|yanine81|LINK
Hi, hope you can help me.
I have a dropdowlist that obtain its values from a sqlDataSource with the following query:
SELECT Row_Id, Concept, Price FROM Default_Values
I would like to fill a textbox with the "Price" field from the query upon the selectedValue of the dropdowlist, all through the sqlDataSource proper functions.
I don't want to call the same query in codebehind, just need to retrieve the thridsqlDataSource value into the textbox.
Thanks in advance. Best regards.
Nov 04, 2011 08:29 PM|b471code3|LINK
You don't want to receive the value from the datasource, you want to retrieve the selected value in the dropdownlist. So create a SelectedIndexChanged event for the dropdownlist and set AutoPostBack="true" on it. Inside the SelectedIndexChanged event,
set TextBox1.Text = DropDownList1.SelectedValue.ToString() This will work as long as the dropdownlist's DataValue property is set to the Price field you mention. Otherwise in the SelectedIndexChanged event you will have to run another query to get the values
based on the selectedvalue of the ddl. OR you could put another sql datasource on the page and configure the select parameter to use a control (dropdownlist). The only problem with this approach is you cannot directly bind a textbox to a datasource, it has
to be in a FormView, GridView, etc in order to work properly.
I also suggest checking out some of the data access videos and how-to pages on this site as they have a lot of info.