Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a dropdown which lists all the items in my database

and i have another texbox which i want it to display the price of the item selected in the dropdown list. how can i do it? should i code inside the textbox or in the dropdownlist? i Tryed to make a code, but i get many errors!

protected void Page_Load(object sender, EventArgs e)
{
	if(!IsPostBack)
	{
		DropDownList1.DataSource = ds; 
		DropDownList1.DataTextField = "ItemName"
		DropDownList1.DataValueField = "Price";
	        DropDownList1.DataBind();
	}
}

protected void DropDownList1_OnSelectedIndexChanged(object sender, EventArgs e)
{
	TextBox1.Text = DropDownList1.SelectedValue;
}
Posted
Comments
Richard C Bishop 9-May-13 15:40pm    
You are on the right track. List all the errors please.
Thanks7872 9-May-13 23:50pm    
Make sure you have AutoPostBack="true" for DropDownList1,thats it.If theres still any error you can post code which you suspect.

Please follow the link

http://www.ezineasp.net/post/ASP-Net-DropDownList-SQL-Datasource-Databinding.aspx[^]

If you what to show the Value of the dropdownlist, then the dropdownlist property AutoPostback must be true as Róhãn Lëuvä said.


Thanks
 
Share this answer
 
But there is no text box involved, the data should be displayed in a text box
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900