Click here to Skip to main content
16,011,626 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello all,

I have a datalist.Inside it has two dropdowns. On the selected index of first dropdown I want to bind the second drop down.for that i have to need the selected value of first drop down.How it will be done bcz i am not getting the selected value of first drop down.

code at selected index
 DropDownList ddlcountry= (DropDownList)DataList1.FindControl("ddlcountry");
int id=convert.toint32(ddlcountry.selectedvalue);

but it shows null at ddlcountry.

Thanks & Regards,
amit
Posted
Updated 22-Mar-11 7:39am
v2
Comments
Wendelius 22-Mar-11 13:40pm    
Pre and code tags added
Orcun Iyigun 22-Mar-11 13:49pm    
Maybe cascading dropdown will work for you?

http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/CascadingDropDown/CascadingDropDown.aspx

http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/Walkthrough/CCDWithDB.aspx

You dont find the control on the DataList itself. You do it on every DataListItem of the DataList. Refer to the code below:

(DropDownList)DataList1.Items[0].FindControl("ddlcountry");
 
Share this answer
 
hi,
FindControl needs to know which Item it is looking in because a
DataList contains many copies of each control that is in a template.You need to iterate all items in DataList to find the dropdown and manipulate them, you can use the code below,

C#
foreach(DataListItem dlistItem in DataList1.Items)
{
   DropDownList ddlcountry=  dlistItem.item[i].
                findControl("ddlcountry") as DropDownList;
   if(ddlcountry!=null)
   {
     int id=Convert.ToInt32(ddlcountry.SelectedValue);
   }

}


Hope this will help.
 
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