本文介绍了动态下拉列表seletedchange更改文本框中的相应列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在它的seletedchange索引事件中动态创建了dropdownlist的任何内容,我编写了代码,我希望如果在dropdown中选择了任何值,它的对应值将出现在
数据库中的标签或文本框.
Dyanmically created no of dropdownlist IN it s seletedchange index event i wrote code i want that if seleted any value in dropdown its correspons value would be come in
label or textbox from database.
DropDownList ddl;
Label la; global declared
for (int i = 0; i < DDLCount; i++)
{
// Create the dropdownlists
ddl = new DropDownList();
la = new Label();
ddl.ID = "Text" + i;
la.ID = "la" + i;
ddl.SelectedIndexChanged += new EventHandler(dd1_SelectedIndexChanged);
//dd2.ID = "Texts" + i;
LiteralControl l1 = new LiteralControl("<br></br>");
SqlConnection con1 = new SqlConnection("Data Source=ABC-0D30299B90A;Initial Catalog=JAPIT;Integrated Security=True");
con1.Open();
string st = "select doe_name from Doe_detail ";
SqlCommand cmd = new SqlCommand(st, con1);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
ddl.Items.Add(dr.GetString(0).ToString());
}
con1.Close();
protected void dd1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con1 = new SqlConnection("Data Source=ABC-0D30299B90A;Initial Catalog=JAPIT;Integrated Security=True");
con1.Open();
string st = "select doe_id from Doe_detail where doe_name=" + ddl.SelectedValue.ToString() + " ";
SqlCommand cmd = new SqlCommand(st, con1);
SqlDataReader dr = cmd.ExecuteReader();
la.Text = dr.GetString(0).ToString();
la.Text = "seleted";
}
// Add it to the panel
Panel3.Controls.Add(ddl);
Panel3.Controls.Add(la);
Panel3.Controls.Add(l1);
}
}
推荐答案
protected void dd1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
SqlConnection con1 = new SqlConnection("Data Source=ABC-0D30299B90A;Initial Catalog=JAPIT;Integrated Security=True");
con1.Open();
string st = "select doe_id from Doe_detail where doe_name=" + ddl.SelectedValue.ToString() + " ";
SqlCommand cmd = new SqlCommand(st, con1);
SqlDataReader dr = cmd.ExecuteReader();
la.Text = dr.GetString(0).ToString();
la.Text = "seleted";
}
catch (Exception ex)
{}
}
这篇关于动态下拉列表seletedchange更改文本框中的相应列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!