Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

So im trying to load a different string when the user has selected a different item, my code:

void ModeSelectorSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var data1 = new string[]
                                        {
                                        "January 2012",
                                        "February 2012",
                                        "March 2012",
                                        "April 2012",
                                        };

        var data2 = new string[]
                                        {
                                        "Married",
                                        "Divorced",
                                        "Buy new house",
                                        "Get promotion",
                                        };
        if (_Menu2.SelectedIndex == 2) {

                _Menu3.ItemsSource = data1;

        }
        else if (_Menu2.SelectedIndex == 3)
            {

                _Menu3.ItemsSource = data2;
            }    

}

When I use just 1 string it works fine, but as soon as I try to load 2 different strings in the same drop down menu it shuts down, meaning that its not showing any string data at all. What am I doing wrong?

share|improve this question
Check whether your control(of which the selected index has to be checked) causes a postback. If so, rebind the drop down menu. – Rohit Kiran 35 mins ago
@RohitKiran No clue how to do that. – Tarayaa 33 mins ago
Are you trying to load data from data1 and data2 into a single drop down. Please be specific. – Rohit Kiran 28 mins ago
Here u are taking _Menu3.ItemsSource. Is this datagrid or something else? – Anurag Jain 19 mins ago
@RohitKiran "I try to load 2 different strings in the same drop down", Yes I am. – Tarayaa 7 mins ago

1 Answer

For ASP.NET WebForms DropDownList follow this code snippet:

_Menu3.DataSource = someData;
_Menu3.DataBind();

Perhaps it would be better to move this logic on a client side and use javascript.

share

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.