开发者

Where Set ListBox Selected index if inside a FormView?

开发者 https://www.devze.com 2022-12-09 12:54 出处:网络
Where in the event li开发者_如何学Cfe cycle should I set the ListBox.SelectedIndex if the Listbox is contained within a FormView? What I\'m trying to do is increase the SelectedIndex by 1 which makes

Where in the event li开发者_如何学Cfe cycle should I set the ListBox.SelectedIndex if the Listbox is contained within a FormView? What I'm trying to do is increase the SelectedIndex by 1 which makes it move from item to item whenever a user clicks on a submit button.


You have to use FindControl to access the listbox and then increment the value. The following code would go in the button submit event:

ListBox myListBox = myFormView.FindControl("myListBox") As ListBox;
if (myListBox != null) {
    myListBox.SelectedIndex++;
}


In the OnClick event handler for the submit button.

You could find the ListBox control from the controls list of the FormView and then increase the selectedIndex

something like this:

    public void Button1_Click(object sender, EventArgs e)
    {
        foreach (Control c in fv1.Controls)
        {
            if (c is ListBox)
            {
                ListBox lbx = c as ListBox;
                ++lbx.SelectedIndex;
            }
        }
    }


Well if you want to increase the selectedindex when a button is clicked, what about increasing it in the button click event? Where are you trying to set it that you're having problems?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号