本文介绍了下拉列表文本更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我写了这段代码,当下拉列表索引更改时加载,但它在索引更改事件和其他文本更改事件中不起作用,但在按钮点击事件中工作。请告知错误是什么?



SqlConnection con = new SqlConnection(连接);

SqlCommand cmd1 = new SqlCommand(选择ID来自测试Name ='+ DropDownList1.Text +',con);



SqlDataAdapter da1 = new SqlDataAdapter(cmd1);



DataSet ds1 = new DataSet();

da1.Fill(ds1);



DropDownList2。 DataTextField = ds1.Tables [0] .Columns [ID]。ToString();

DropDownList2.DataValueField = ds1.Tables [0] .Columns [ID]。ToString();



DropDownList2.DataSource = ds1.Tables [0];

DropDownList2.DataBind();

Hi,

I have wrote this code to load when drop down list index change, but it doesn't working in index change event and other text change event, but working in button click event. Please advise what is the wrong?

SqlConnection con = new SqlConnection(connection);
SqlCommand cmd1 = new SqlCommand("Select ID from Test where Name='" + DropDownList1.Text + "'", con);

SqlDataAdapter da1 = new SqlDataAdapter(cmd1);

DataSet ds1 = new DataSet();
da1.Fill(ds1);

DropDownList2.DataTextField = ds1.Tables[0].Columns["ID"].ToString();
DropDownList2.DataValueField = ds1.Tables[0].Columns["ID"].ToString();

DropDownList2.DataSource = ds1.Tables[0];
DropDownList2.DataBind();

推荐答案


这篇关于下拉列表文本更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 06:46