Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
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.
Posted

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
 
Share this answer
 
v2
Comments
Tom Marvolo Riddle 22-Apr-14 2:36am    
Hi siva,the link which you posted redirect to the same question
Siva Hyderabad 22-Apr-14 2:41am    
hi,thanks jas,i updated with new link
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[^]
 
Share this answer
 
Comments
Member 10755393 22-Apr-14 3:48am    
i want implement in 3 3 tier artchitecture....ididn't find any link in google please help me with sample code
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900