Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
in my applications two dropdowns are there one is one page and another one another page both are bind same values.

in my issue is when i select a value that value bind to another dropdown

i am trying this code

ddlyears.Items.FindByValue(ddlfor.SelectedValue);

but it's not working

please give any idea to me.
Posted

Add a SelectedIndexChanged event for ddlyears and set the Autopostback property to True.

In the SelectedIndexChanged event add

C#
protected void ddlyears_SelectedIndexChanged(object sender, EventArgs e)
        {
            ddlfor.SelectedValue = ddlyears.SelectedValue;// Both have same bound values
        }


Note: As per OP comment , Both DropDowns are in same Page and having same bound data.
 
Share this answer
 
v2
C#
ddlyears.Items.FindByValue(ddlfor.SelectedValue).Selected =true;
 
Share this answer
 
Comments
krish2013 23-Jan-14 1:22am    
Hii Karthikk,
Thanks for replyed to me.i tried that but it's not working
please give any alternative idea
Karthik_Mahalingam 23-Jan-14 1:24am    
ddlyears and ddlfor in same page ??
both are having same dataonly ?
krish2013 23-Jan-14 1:30am    
ya same page
krish2013 23-Jan-14 1:30am    
and same data
Karthik_Mahalingam 23-Jan-14 1:54am    
try this
var text = ddlfor.SelectedItem.Text;
int index = ddlyears.Items.IndexOf(new ListItem(text));
ddlyears.SelectedIndex = index;

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