Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 3 dropdownlist in my page for country,state,city
selecting country, state drpdwn list should automatically will bind.and as that by selecting state,city dropdown list should be binded
please help me out soon
thank you
Posted

Subscribe to the DDL.SelectedIndexChanged event and populate the next DDL in the postback.

You could wrap this in an UpdatePanel to make it a partial page refresh.
 
Share this answer
 
Comments
pal5hah 18-Oct-11 5:38am    
can you give me sample code for that..and as well as its dal and bll structure also
 
Share this answer
 
v3
Comments
pal5hah 18-Oct-11 5:41am    
this link is not working
You should bind your data when the selected index change event.

C#
protected void dlstcountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        string messg = "";
        DataTable dtstate = new DataTable();

       
      sql = "Select State from Tablename where Country='"+dlstcountry.SelectedValue.Trim()+ "'";
        dtstate = GetRecord(sql, ref messg);
        dlststate .Items.Clear();
        if (dtstate .Rows.Count != 0)
        {
            for (int i = 0; i < dtstate .Rows.Count; i++)
            {
                dlststate.Items.Add(new ListItem(dtstate .Rows[i][0].ToString()));
            }
        }

    }



Hope Be helpful,
Theingi Win
 
Share this answer
 
 
Share this answer
 
Hi, Pal

When ur working with drop down list control u need to understand what is server side code and what is client side code

when u working with dropdown list u simply add AutoPostBack = "True" to the control in the page. that's it when ur change the selected item in list it fires the
ddlCtrl_OnSelectedIndexChanged(object sender, EventArgs e) 
event and corosponding code is executed.

For ur problem

Simple Solution is Put the 3 dropdown controls in a updatepanel and write a code like
ddc1_OnSelectedIndexChanged(object sender, EventArgs e)
{
ddc2.datasource = ds1 //Dataset Or List
}

<pr2 lang="cs">ddc2_OnSelectedIndexChanged(object sender, EventArgs e)
{
ddc3.datasource = ds2 //Dataset Or List
}</pr2>


Thanks...
 
Share this answer
 
Hi,

Here is my solution check this once

ASP.NET
<asp:scriptmanager id="ScriptManager1" runat="server" xmlns:asp="#unknown">
   </asp:scriptmanager>
   <asp:updatepanel id="UpdatePanel1" runat="server" xmlns:asp="#unknown">
      <contenttemplate>
        <table width="100&" align="center">
         <tr>
           <td>Select Contry</td>
           <td>
               <asp:dropdownlist id="DropDownList1" runat="server" datatextfield="cname" datavaluefield="cid">
                   onselectedindexchanged="DropDownList1_SelectedIndexChanged">
               </asp:dropdownlist>
           </td>
         </tr>
         <tr>
           <td>Select State</td>
           <td><asp:dropdownlist id="DropDownList2" runat="server" datatextfield="sname" datavaluefield="sid">
                   onselectedindexchanged="DropDownList2_SelectedIndexChanged">
               </asp:dropdownlist></td>
         </tr>
         <tr>
           <td>Select City</td>
           <td><asp:dropdownlist id="DropDownList3" runat="server" datatextfield="cityname" datavaluefield="cityid">
               </asp:dropdownlist></td>
         </tr>
        </table>
      </contenttemplate>
   </asp:updatepanel>


In the code behind file contains following code

C#
AddressBLL objbll = new AddressBLL();
//this is your BLL class object for accessing all methods
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        fillcontry();
    }

}
public void fillcontry()
{
    DataTable dt = new DataTable();
    dt = objbll.getAllContries();
    DropDownList1.DataSource = dt;
    DropDownList1.DataBind();
}


protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
     DataTable dt = new DataTable();
    dt = objbll.getStatesbyCid(DropDownList1.SelectedIndex);
    DropDownList2.DataSource = dt;
    DropDownList2.DataBind();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
    DataTable dt = new DataTable();
    dt = objbll.getCitiesbySid(DropDownList2.SelectedIndex );
    DropDownList3.DataSource = dt;
    DropDownList3.DataBind();
}


All the Best
 
Share this answer
 
Comments
pal5hah 18-Oct-11 9:09am    
thnx alot..its DONE
Muralikrishna8811 18-Oct-11 9:58am    
most welcome
pal5hah 19-Oct-11 8:24am    
u didnt gave me that answer for multiple delete
Muralikrishna8811 19-Oct-11 13:33pm    
I thought u got answer for that.

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