Accordion SelectedIndex behind code of last item selected?

雨燕双飞 提交于 2019-12-24 20:12:18

问题


is it possible in behind code to set the SelectedIndex of an accordion to the same Index of what the user just click?


回答1:


    Accordion.SelectedIndex = -1;
    Accordion.RequireOpenedPane = false;



回答2:


My Solution:

  1. Set a cookie on SelectedIndexChanged using javascript
  2. Read the cookie on the page load event
  3. Set the SelectedIndex

At the top of your page, using accordion control ID Accordion1:

<script type="text/javascript" language="javascript">        
function createCookie(name, value, days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            var expires = "; expires=" + date.toGMTString();
        } else var expires = "";
        document.cookie = escape(name) + "=" + escape(value) + expires + "; path=/";
    }

    function readCookie(name) {
        var nameEQ = escape(name) + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length, c.length));
        }
        return null;
    }

    function pageLoad() {
        var current_path = window.location.pathname.split('/').pop();
        console.log('current path:'+current_path);
        $find('Accordion1_AccordionExtender').add_selectedIndexChanged(onAccordionPaneChanged);

        var idx = readCookie('a_index');

        changeSelected(idx);
        $find('Accordion1_AccordionExtender').set_TransitionDuration(50);
    }

    // expand given accordion pane
    function changeSelected(idx) {

        $find('Accordion1_AccordionExtender').set_SelectedIndex(idx);

    }
    function onAccordionPaneChanged(sender, eventArgs) {
        var selPane = sender.get_SelectedIndex();
        // alert('You selected Pane ' + selPane);
        createCookie('a_index', selPane, 1);

    }
</script>

In the code behind:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim si As String = String.Empty 'selected index 

        If Request.Cookies("a_index") IsNot Nothing Then

            si = Request.Cookies("a_index").Value

            If si <> String.Empty Then
                Accordion1.SelectedIndex = si
            End If

        End If

    End Sub


来源:https://stackoverflow.com/questions/8188488/accordion-selectedindex-behind-code-of-last-item-selected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!