Click here to Skip to main content
12,403,983 members (76,432 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
Hi,
Iam trying to display a gridview inside an accordion.But it is not working.The accordion is working fine except with the gridview.I searched and experimented something with my code but it is not working.Please review this piece of code and help to make necessary changes.

jquery part for accordion:-

$("#accordion > li > div").click(function () {
 
    if (false == $(this).next().is(':visible')) {
        $('#accordion ul').slideUp(300);
    }
    $(this).next().slideToggle(300);
});

aspx part for accordion,with gridview

<ul id="accordion">
              <li>
                  <div>
                      Consumption(kWH)</div>
                  <ul>
                      <asp:GridView ID="ConsumptionGrid" runat="server" AutoGenerateColumns="False" AllowSorting="True"
                          OnSorting="GridViewSorting" OnRowDataBound="GridView1RowDataBound">
                          <Columns>
                              <asp:BoundField DataField="DEPOSIT_DATE" HeaderText="Date" />
                              <asp:BoundField DataField="CURRENT_BALANCE" HeaderText="BalanceAmount" />
                          </Columns>
                      </asp:GridView>
                  </ul>
              </li>
              <li>
                  <div>
                      Messages</div>
                  <ul>
                      <asp:GridView ID="ConsumerGrid" runat="server" AutoGenerateColumns="False" AllowSorting="True"
                          OnSorting="GridViewSorting" OnRowDataBound="GridView1RowDataBound">
                          <Columns>
                              <asp:BoundField DataField="WARNING_DATE" HeaderText="Date" />
                              <asp:BoundField DataField="WARNING_MESSAGE" HeaderText=" Warnings" />
                          </Columns>
                      </asp:GridView>
                  </ul>
              </li>
          </ul>

In the c# page I have done code for gridview,iam not copying it here because the gridview is working fine without the accordion.Please review the code and suggest necessary changes.
Posted 27-Dec-12 17:02pm
danil33399
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

try this

<ul id="accordion">
              <li>
                  <div>
                      Consumption(kWH)</div>
                  <ul><li>
                      <asp:GridView ID="ConsumptionGrid" runat="server" AutoGenerateColumns="False" AllowSorting="True"
                          OnSorting="GridViewSorting" OnRowDataBound="GridView1RowDataBound">
                          <Columns>
                              <asp:BoundField DataField="DEPOSIT_DATE" HeaderText="Date" />
                              <asp:BoundField DataField="CURRENT_BALANCE" HeaderText="BalanceAmount" />
                          </Columns>
                      </asp:GridView></li>
                  </ul>
              </li>
              <li>
                  <div>
                      Messages</div>
                  <ul><li>
                      <asp:GridView ID="ConsumerGrid" runat="server" AutoGenerateColumns="False" AllowSorting="True"
                          OnSorting="GridViewSorting" OnRowDataBound="GridView1RowDataBound">
                          <Columns>
                              <asp:BoundField DataField="WARNING_DATE" HeaderText="Date" />
                              <asp:BoundField DataField="WARNING_MESSAGE" HeaderText=" Warnings" />
                          </Columns>
                      </asp:GridView></li>
                  </ul>
              </li>
          </ul>
  Permalink  
Comments
danil33 28-Dec-12 0:59am
   
Thanks Ashish,
It is working fine now.
AshishChaudha 28-Dec-12 1:31am
   
Thanks
_Amy 28-Dec-12 1:01am
   
My +5! I din't concentrated on ListItem Hierarchy. :)
AshishChaudha 28-Dec-12 1:31am
   
hmm..Thanks
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

If you find in page source, you'll find that your gridview is rendered properly. Make sure that you are not hiding it somewhere with accordian style. Just take a review and try to find the exact place.

Anyway, you can make it visible in your jquery snippet(Not a good practice, find the root cause first). Try this
$("#accordion > li > div").click(function () {
 
    if (false == $(this).next().is(':visible')) {
        $('#accordion ul').slideUp(300);
        //here you make your grid or inner panel content visible.
    }
    $(this).next().slideToggle(300);
});


Hope it helps.
--Amit
  Permalink  
Comments
danil33 28-Dec-12 0:58am
   
Hi Amit,
Thanks for the response.
_Amy 28-Dec-12 0:59am
   
Welcome. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 27 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100