从一个dwon到另一个dwon获取值 [英] Getting values from one drop dwon to another
问题描述
我有点混淆......我有两个下拉列表,其中一个下拉列表的值来自数据库(我已经为它编写了一个C#代码),现在我要做的是,当从第一个下拉列表中选择一个特定值时,我希望第二个下拉列表只显示一些值,这些值应该来自另一个数据库。
例如,如果第一个下拉列表中有EC,CS等部门,第二个下拉列表有名称,当我选择Ec时,所有属于EC部门的名称都应出现在第二个下拉列表。这可能吗?...我设法写了几行代码...
Hi,
I have a slight confusion...I have two Drop down list and the values for one of the drop down list are derived from the database(I have written a C# code for it),Now what i want to do is ,when a particular value is selected from the first drop down list I want the second Drop down list to display only a few values which should be derived from another database.
for instance if first drop down list has departments like EC,CS etc. and the second drop down list has names,When I select Ec,all the names belonging to EC department should appear in the second drop down list.is this possible?...I managed to write few lines of code...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Data.OleDb;
public partial class Forms_Master_Forms_Temporary_duty_form : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("Server=SOFTDEV1; Database=ADE_2903_SOFTDEV; Integrated security = true");
protected void Page_Load(object sender, EventArgs e)
{
DropDownList7.Visible = false;
if (!IsPostBack)
{
GetData();
txtdate.Text = DateTime.Now.ToShortDateString();//get the current date into the textbox
//adding the states in the drop down box
add_states();
}
}
protected void GetData()
{
SqlCommand cmd = new SqlCommand("select * from M_Division ", conn);
SqlDataAdapter sd = new SqlDataAdapter(cmd);
conn.Open();
DataTable dt = new DataTable();
sd.Fill(dt);
DropDownList3.DataSource = dt;
DropDownList3.DataTextField = "DivShort";
DropDownList3.DataValueField = "DivShort";
DropDownList3.DataBind();
conn.Close();
}
这只是将数据绑定到下拉列表。我不知道如何从数据库中获取值到第二个下拉列表中从第一个数据库中选择第一个值。
This is only to bind data to drop down list..Well I am not sure how to get values into the second drop down list from database when the first value is selected from the first database.
推荐答案
这可以帮到你
http://forums.asp.net/p/1858208/5209467.aspx/1?Re +级联+下拉列表 [ ^ ]
我会告诉你答案是逻辑而不是代码..所有我会说你会在.net visual studio和C#中找到它并且它会工作
优先:转到DropDownList3的属性并将其设置为autopostback
然后:转到DropDownList3事件onSelectedIndexChanged并写入内部代码
if(DropDownList3.se lectedValue> 0)
{
DropDownList7.visible = true;
fillDropDownList7();
}
测试并询问我是否需要任何东西。
最好的问候,
Ibrahim Karakira
I will tell you the answer as logic not code.. all what I will say you will find in .net visual studio and C# and it will work
first: go to the properties of DropDownList3 and set it as autopostback
then: go to the DropDownList3 event onSelectedIndexChanged and write the code inside
if (DropDownList3.selectedValue>0)
{
DropDownList7.visible=true;
fillDropDownList7();
}
Test it and ask me if you need anything.
Best Regards,
Ibrahim Karakira
您好,
在这种情况下,您需要为第一个Dropdwon列表使用Selected Index Change事件。请查看下面的链接以获取更多详细信息.Hope这对你有帮助。
http://www.dotnetfunda.com/forums/thread2590-filling-a-dropdownlist-on-selectedindexchanged-of-another-dropdownlist.aspx [ ^ ]
从这里检查解决方案2.
DropDownList并在SelectedIndexChanged事件后捕获值 [ ^ ]
Hi,
In this case you need to use Selected Index Change event for the first Dropdwon list.Check the link below for more details.Hope this will help you.
http://www.dotnetfunda.com/forums/thread2590-filling-a-dropdownlist-on-selectedindexchanged-of-another-dropdownlist.aspx[^]
Check Solution 2 from here.
DropDownList and capturing values after SelectedIndexChanged event[^]
这篇关于从一个dwon到另一个dwon获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!