Cascading DropdownList

Posted by Suneel161 under Regular Expressions on 3/22/2010 | Views : 6441 | Status : [Member] | Replies : 5
Hi all,

I have two dropdownlists in my webpage.. am filling these dropdownlist with values 1,2,3,4.... like
<asp:DropDownList ID="ddl_vacancies" runat="server" >
<asp:ListItem Value="0">0</asp:ListItem>
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>

</asp:DropDownList> so on..
when i select DDL1 automatically display those values in DDL2...




Responses

Posted by: Sagarp on: 3/23/2010 [Member] Bronze

Up
0
Down
Read following article

http://www.aspsnippets.com/Articles/Creating-Cascading-DropDownLists-in-ASP.Net.aspx



Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bhavna81 on: 3/23/2010 [Member] Starter

Up
0
Down
Hi,
make Autopostback property to true to your first DDL ddl_vacancies. next, on Selected indexchange event of ddl_vacancies set the second DDL text like..
[code]
SecondDDL.SelectedText=FirstDDL.SelectedIndex.Text;
[/code]

thanks

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Johan on: 12/8/2011 [Member] Starter | Points: 25

Up
0
Down
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string s = DropDownList1.SelectedValue.ToString();
DropDownList2.Items.Add(s);
}
}


Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksingh on: 12/8/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

Try below link for proper implementation
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx

Regards,
Sunil

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Varung on: 12/9/2011 [Member] Starter | Points: 25

Up
0
Down
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (ListItem text in DropDownList1.Items)
{
DropDownList2.Items.Add(text);
DropDownList2.DataBind();

}
}
above code adds all the items of ddl1 to ddl2

G.Varun

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response