链接DropDownList,带有sql数据库的文本框 [英] Link DropDownList, textbox with sql database

查看:81
本文介绍了链接DropDownList,带有sql数据库的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表,其中列出了我数据库中的所有项目



我有另一个texbox,我希望它显示所选项目的价格下拉列表。我该怎么做?我应该在文本框内还是在下拉列表中编码?我尝试制作代码,但是我收到很多错误!



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;
}

推荐答案

请点击链接



< a href =http://www.ezineasp.net/post/ASP-Net-DropDownList-SQL-Datasource-Databinding.aspx> http://www.ezineasp.net/post/ASP-Net-DropDownList-SQL -Datasource-Databinding.aspx [ ^ ]



如果你要显示下拉列表的值,那么dropdownlist属性 AutoPostback必须是true as RóhãnLëuvä说。





谢谢
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


但是没有涉及文本框,数据应该显示在文本框中
But there is no text box involved, the data should be displayed in a text box


这篇关于链接DropDownList,带有sql数据库的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆