locked
From Selected event of Gridview Child control retrieve the selected HeaderTemplate value from Accordian RRS feed

  • Question

  • User1909155429 posted

    I want to be able to get the selected value of Linkbutton that resides inside Accordian <headertemplate>,

    while the Gridview row is selected,

    which  resides inside the <ContentTemplate> ?

     

    Pete

    Monday, May 18, 2015 9:39 AM

Answers

  • User61956409 posted

    Hi Pete,

    You could save the selected header value in a HiddenField when you click the header, then you could get the value from HiddenField.

    <asp:HiddenField ID="hf_selectedheader" runat="server" Value="" />
    <script>
        $(function () {
            var header = $(".accordion-selected").text();
            $("#hf_selectedheader").val(header);
    
            $(".accordion-header").click(function () {
                var header = $(".accordion-selected").text();
                //alert(header);
                $(this).val(header);
            })
    
            $(".accordion-selected").click(function () {
                var header = $(".accordion-selected").text();
                //alert(header);
                $(this).val(header);
            })
        })
    </script> 
    
    string header = hf_selectedheader.Value.ToString();

    Best Regards,

    Fei Han




    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 4, 2015 5:57 AM

All replies

  • User61956409 posted

    Hi Pete,

    Thanks for your post.

    Could you post the relevant code? We need to reproduce the problem according to your code.

    Best Regards,

    Fei Han

    Monday, May 18, 2015 11:28 PM
  • User1909155429 posted
    I can get the gridview value if I add a command argument but having difficulty getting the selected  header value at the same stage.
    I don't know which event or how I should reference them?  
    
    <ajaxToolkit:Accordion ID="Accordion1" runat="server" TransitionDuration="100"  SelectedIndex=-1 FramesPerSecond="200" FadeTransitions="true" RequireOpenedPane="false" OnItemDataBound="Accordion1_ItemDataBound"
        ContentCssClass="accordion-content" HeaderCssClass="accordion-header" HeaderSelectedCssClass="accordion-selected" >
        <HeaderTemplate>
            <asp:LinkButton ID="LinkButton1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "category")%>' ></asp:LinkButton>
               </HeaderTemplate>
        <ContentTemplate>
            <asp:HiddenField ID="txt_categoryID" runat="server" Value='<%#DataBinder.Eval(Container.DataItem,"category") %>' />
            <asp:GridView ID="GridView1" runat="server" RowStyle-BackColor="#ededed" RowStyle-HorizontalAlign="Left"
                AutoGenerateColumns="false" GridLines="None" CellPadding="2"
    CellSpacing="2"
                Width="300px">
                <Columns>
                    <asp:TemplateField HeaderStyle-HorizontalAlign="Left" HeaderText="Type" HeaderStyle-BackColor="#d1d1d1"
                        HeaderStyle-ForeColor="#777777">
                        <ItemTemplate>
                            <%#DataBinder.Eval(Container.DataItem, "type")%>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </ContentTemplate>
    </ajaxToolkit:Accordion>

    Thursday, May 21, 2015 6:38 PM
  • User61956409 posted

    Hi Pete,

    You could save the selected header value in a HiddenField when you click the header, then you could get the value from HiddenField.

    <asp:HiddenField ID="hf_selectedheader" runat="server" Value="" />
    <script>
        $(function () {
            var header = $(".accordion-selected").text();
            $("#hf_selectedheader").val(header);
    
            $(".accordion-header").click(function () {
                var header = $(".accordion-selected").text();
                //alert(header);
                $(this).val(header);
            })
    
            $(".accordion-selected").click(function () {
                var header = $(".accordion-selected").text();
                //alert(header);
                $(this).val(header);
            })
        })
    </script> 
    
    string header = hf_selectedheader.Value.ToString();

    Best Regards,

    Fei Han




    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 4, 2015 5:57 AM
  • User1909155429 posted

    Thanks

    Have you a example written in javascript ?

    Tuesday, June 16, 2015 11:57 AM