我有3个下拉菜单和3层建筑物 [英] i have 3 dropdowns and populating with 3 tier architeture
问题描述
这个 vijay任何人都可以告诉我如何 3 下拉列表 3tierArchitecture。
即iam 3 dropdownlist ddlcountry, ddlstate , ddlcity。 如果 i 选择 ddlcountry中的code-string> india 我应该获得的 india ddlstate中的class =code-keyword> 和 如果 i 选择 AP 在 ddlstate 然后我应该得到的 AP 在 ddlcity。
看到这个链接,它将dropdownlist控件互相填充
http://www.aspdotnet-suresh.com/2010/10/how-to-populate-dropd own-based-on-other.html [ ^ ]
您可以将此示例与3层艺术结构一起使用
<试试这个,
这里,三个AJAX级联下拉列表以及三个相应的ASP.Net DropDownLists将从SQL Server数据库填充,其中包含使用Web Service和Web的Country State City的值方法。
http:// www.aspsnippets.com/Articles/AJAX-Cascading-DropDownList-sample-with-database-using-ASPNet.aspx [ ^ ]
创建一个webApplication和两个classLibrary。
在Web Appl中ication:
Aspx代码页面:
< form id =form1runat =server>
< div>
< asp:dropdownlist id =Countryrunat =serverxmlns:asp =#unknown>
onselectedindexchanged =CountryValueSelectedIndexChanged
AutoPostBack =True>
< / asp:dropdownlist>
< br />
< asp:dropdownlist id =Staterunat =serverxmlns:asp =#unknown>
< / asp:dropdownlist>
< / div>
< / form>
Aspx.cs中的代码页面:
BusinessLogic businessLogic = new BusinessLogic();
protected void Page_Load(object sender,EventArgs e)
{
if(!IsPostBack)
{
CountryBind();
}
}
public void CountryBind()
{
DataSet countryDataSet = businessLogic.CountryValues();
Country.DataSource = countryDataSet;
Country.DataTextField =CountryName;
Country.DataValueField =ID;
Country.DataBind();
Country.Items.Insert(0,new ListItem( - Select - ,0));
}
protected void CountryValueSelectedIndexChanged(object sender,EventArgs e)
{
int countryid = Convert.ToInt32(Country.SelectedValue);
DataSet countryDataSet = businessLogic.selectState(Country.SelectedIndex);
State.DataSource = countryDataSet;
State.DataTextField =StateName;
State.DataValueField =CountryCode;
State.DataBind();
}
创建一个名为BusinessLayer的类库。将Program.cs重命名为BusinessLogic.cs。
BusinessLogic.cs中的代码为:
公共类BusinessLogic
{
DataLogic dbProgram = new DataLogic();
public DataSet selectState(int countryValue)
{
return dbProgram.returnState(countryValue);
}
public DataSet CountryValues()
{
return dbProgram.Countries();
}
}
创建一个名为DataLayer的类库。将Program.cs重命名为DataLogic.cs。
DataLogic.cs中的代码为:
公共类DataLogic
{
SqlConnection con = new SqlConnection(Data Source = HYD-NPULIVARTHY; Initial Catalog = test2; Integrated Security = True);
public DataSet returnState(int countryId)
{
// SqlConnection con = new SqlConnection(Data Source = HYD-NPULIVARTHY; Initial Catalog = test2; Integrated Security = True);
con.Open();
SqlCommand cmd = new SqlCommand(select * from State where CountryCode ='+ countryId +',con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
cmd.ExecuteNonQuery();
da.Fill(ds);
con.Close();
返回ds;
}
公共数据集国家()
{
con.Open();
SqlCommand cmd = new SqlCommand(select * from CountryState,con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
cmd.ExecuteNonQuery();
da.Fill(ds);
con.Close();
返回ds;
}
}
创建创建3个图层后,转到Web应用程序,然后转到参考。
右键点击参考文献 - >选择Project并选择BusinessLayer Reference。
转到BusinessLayer然后转到引用。
右键单击引用 - >选择Project并选择DataLayer Reference。
这是实现的方式。
hi,
this is vijay can anyone tell me how to work with 3 dropdownlist in 3tierArchitecture.
i.e iam having 3 dropdownlist "ddlcountry", "ddlstate", "ddlcity". if i select "india" in ddlcountry i should get states of india in ddlstate and if i select the "AP" in ddlstate then i should get the cities of AP in ddlcity.
see this link , it populate dropdownlist control one to another
http://www.aspdotnet-suresh.com/2010/10/how-to-populate-dropdown-based-on-other.html[^]
you can use this example with your 3 tier artchitecture
Try this,
Here,Three AJAX Cascading Dropdowns along with the three corresponding ASP.Net DropDownLists will be populated from SQL Server database with values of Country State City using Web Service and Web Methods.
http://www.aspsnippets.com/Articles/AJAX-Cascading-DropDownList-sample-with-database-using-ASPNet.aspx[^]
Hi,
Create one webApplication, and two classLibrary.
In Web Application:
Code In Aspx Page:
<form id="form1" runat="server"> <div> <asp:dropdownlist id="Country" runat="server" xmlns:asp="#unknown"> onselectedindexchanged="CountryValueSelectedIndexChanged" AutoPostBack="True"> </asp:dropdownlist> <br /> <asp:dropdownlist id="State" runat="server" xmlns:asp="#unknown"> </asp:dropdownlist> </div> </form>
Code with in Aspx.cs Page:
BusinessLogic businessLogic = new BusinessLogic(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { CountryBind(); } } public void CountryBind() { DataSet countryDataSet = businessLogic.CountryValues(); Country.DataSource = countryDataSet; Country.DataTextField = "CountryName"; Country.DataValueField = "ID"; Country.DataBind(); Country.Items.Insert(0,new ListItem("-- Select --", "0")); } protected void CountryValueSelectedIndexChanged(object sender, EventArgs e) { int countryid = Convert.ToInt32(Country.SelectedValue); DataSet countryDataSet = businessLogic.selectState(Country.SelectedIndex); State.DataSource = countryDataSet; State.DataTextField = "StateName"; State.DataValueField = "CountryCode"; State.DataBind(); }
Create one class Library named as BusinessLayer. With in that rename Program.cs to BusinessLogic.cs.
Code with in BusinessLogic.cs is:
public class BusinessLogic { DataLogic dbProgram = new DataLogic(); public DataSet selectState(int countryValue) { return dbProgram.returnState(countryValue); } public DataSet CountryValues() { return dbProgram.Countries(); } }
Create one class Library named as DataLayer. With in that rename Program.cs to DataLogic.cs.
Code with in DataLogic.cs is:
public class DataLogic { SqlConnection con = new SqlConnection("Data Source=HYD-NPULIVARTHY;Initial Catalog=test2;Integrated Security=True"); public DataSet returnState(int countryId) { // SqlConnection con = new SqlConnection("Data Source=HYD-NPULIVARTHY;Initial Catalog=test2;Integrated Security=True"); con.Open(); SqlCommand cmd = new SqlCommand("select * from State where CountryCode='" + countryId + "'", con); cmd.CommandType = CommandType.Text; SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); cmd.ExecuteNonQuery(); da.Fill(ds); con.Close(); return ds; } public DataSet Countries() { con.Open(); SqlCommand cmd = new SqlCommand("select * from CountryState", con); cmd.CommandType = CommandType.Text; SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); cmd.ExecuteNonQuery(); da.Fill(ds); con.Close(); return ds; } }
After creating creating 3 Layers, goto Web Application then goto References.
RightClick on the References-> select Project and select BusinessLayer Reference.
Goto BusinessLayer then goto References.
RightClick on the References-> select Project and select DataLayer Reference.
This is the way to implement.
这篇关于我有3个下拉菜单和3层建筑物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!