Bootstrap Accordion Group Collapse

In my current webforms application, I am generating a datagrid using a single template column to bind all of the data in each row.

My goal is to utilize the bootstrap accordion panel to show just the order name in the accordion heading and then expand the details of the order in the accordion body.

The issue I'm encountering is that since I'm using C# code to bind the data, every row generated has the same div id. This results in the collapse command collapsing only the first row. Switching it to collapse a class collapses every row in the grid. Is there a way to collapse only the divs in the accordion group where the control resides instead of collapsing by id or class?

Below is the code I have, any assistance would be welcomed:

asp:DataGrid ID="DataGrid_Quotes" CssClass="dataGrid" AutoGenerateColumns="false" runat="server" OnItemDataBound="DataGrid_Quotes_OnItemDataBound">
    <HeaderStyle CssClass="dataGridHeader"></HeaderStyle>
    <Columns>
        <asp:TemplateColumn>
            <ItemTemplate>
                <div class="dataRowItem">
                    <div class="accordion-group">
                        <div class="accodrion-heading">
                            <div class="dataGridMainItem">
                                <div class="container-fluid">
                                    <div class="col-sm-6">
                                        <asp:HyperLink runat="server" Text='<%# Eval("Title") %>' NavigateUrl='<%# Eval("Sale","QuoteDetails.aspx?SaleId={0}") %>' />
                                    </div>
                                    <div class="col-sm-6" align="right">
                                        <asp:Label runat="server" Text='<%# Eval("Quote") %>' />&nbsp;&nbsp;
                                        <a class="accordion-toggle" href="#collapseOne" data-toggle="collapse">
                                            <span class="glyphicon glyphicon-chevron-down"></span></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div id="collapseOne" class="accordian-body in collapse">
                            <div class="accordion-inner">
                                <div class="container-fluid">
                                    <div class="row">
                                        <div class="dataGridItemBody">
                                            <div class="col-sm-6">
                                                Client:&nbsp;<asp:Label runat="server" Text='<%# Eval("Client") %>' />
                                                <br />
                                                Total:&nbsp;<asp:Label runat="server" Text='<%# String.Format(Eval(("Total"), "{0:c}")) %>' />
                                                <br />
                                            </div>
                                            <div class="col-sm-6" align="right">
                                                Created On:&nbsp;<asp:Label runat="server" Text='<%# Convert.ToDateTime(Eval("Created On")).ToString("d") %>' />
                                                <br />
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <br />
                            </div>
                        </div>
                    </div>
                </div>
            </ItemTemplate>
        </asp:TemplateColumn>
    </Columns>
</asp:DataGrid>

Answer №1

I managed to solve the issue by using a "class="collapse" and dynamically setting the data-target attribute to "#<%# Eval("Quote") %>" which assigns the div id to the quote number for each row.

<asp:TemplateColumn>
    <ItemTemplate>
        <div class="dataRowItem">
            <div class="accordion" id="accordion2">
                <div class="accordion-group">
                    <div class="accodrion-heading">
                        <div class="dataGridMainItem">
                            <div class="container-fluid">
                                <div class="col-sm-6">
                                    <asp:HyperLink runat="server" Text='<%# Eval("Title") %>' NavigateUrl='<%# Eval("Sale","QuoteDetails.aspx?SaleId={0}") %>' />
                                </div>
                                <div class="col-sm-6" align="right">
                                    <asp:Label runat="server" Text='<%# Eval("Quote") %>' />&nbsp;&nbsp;
                                    <a class="accordion-toggle" data-toggle="collapse" data-target="#<%# Eval("Quote") %>"><span class="glyphicon glyphicon-chevron-down"></span></a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="accordion-inner">
                        <div id="<%# Eval("Quote") %>" class="collapse">
                            <div class="container-fluid">
                                <div class="row">
                                    <div class="dataGridItemBody">
                                        <div class="col-sm-6">
                                            Client:&nbsp;<asp:Label runat="server" Text='<%# Eval("Client") %>' />
                                            <br />
                                            Total:&nbsp;<asp:Label runat="server" Text='<%# String.Format(Eval(("Total"), "{0:c}")) %>' />
                                            <br />
                                        </div>
                                        <div class="col-sm-6" align="right">
                                            Created On:&nbsp;<asp:Label runat="server" Text='<%# Convert.ToDateTime(Eval("Created On")).ToString("d") %>' />
                                            <br />
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </ItemTemplate>
</asp:TemplateColumn>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Incorporate Thymeleaf's HTML using the powerful JavaScript framework, jQuery

I am facing an issue where the Thymeleaf rendered HTML code is not being displayed by the Browser when I try to insert it using JavaScript. $('<span [[$ th:text#{some.property.key}]] id="counter" class="UI-modern"> </ ...

Choose the current div using JavaScript

Looking to add the selected product along with its quantity and price to another div tag using the jQuery click function. Each time I click, only the first array value of the variable "product" is displayed. How can I access the values of the current row ...

Maintaining equal heights for divs in jQuery upon resizing

I have been attempting to dynamically set the height of all my divs to match the highest div upon page load and window resize. Below is the code snippet I am using: // function to equalize column heights function eqColumn(){ if ($(window).width() > ...

What is the most effective way to save and access British pound symbols?

Every so often, I face this issue where I end up resorting to a messy workaround. There must be a correct way to handle it though, as it's common to work with UK pound symbols. The dilemma is this: when the user inputs a UK pound symbol (£) into a t ...

`Loading CSS files in Node.js with Express``

My CSS isn't loading properly when I run my HTML file. Even though the HTML is correctly linked to the CSS, it seems like express and node.js are not recognizing it. I find it confusing to understand the articles, tutorials, and stack overflow questio ...

Navigating a Bootstrap modal using arrow keys for scrolling - up and down

I attempted to address this issue by using the following code: // here, 'this' represents the modal $(this).focus(); Despite trying the above solution and even attempting to trigger a click event on it, I was unable to get it to work! UPDATE ...

The content in my textarea disappears once the submit button is clicked

I have a script that deletes the text from my textarea after a user clicks the submit button. However, I would like the text to remain in the textarea after submission. <form action="/search" name="myform" id="formid" method="post"> <div cla ...

Aligning a rotated paragraph in the middle of its parent container

Here is my current progress: http://jsfiddle.net/2Zrx7/2/ .events{ height:100px; position: relative; } .tt_username{ position: absolute; top:0px; height: 100%; width: 30px; background: #ccc; text-align: center; } .tt_usern ...

Caching AJAX responses and utilizing an onclick event within a function

Utilizing AJAX to perform server-side actions and update a table on the page without refreshing it initially worked seamlessly. However, I encountered an issue when attempting to send an email through a PHP function using AJAX. Upon triggering the action f ...

Having trouble with the functionality of a simple jQuery toggle menu on mobile?

I am experiencing an issue with a simple toggle menu that utilizes jQuery's on: tap feature, but it is not functioning as expected: <nav id="mobile-nav"> <ul> <li>Item 1</li> <li>Item 2</li> ...

The transition from ExtJS 4 to ExtJS 5: A comprehensive guide

We're in the process of transitioning a web application from ExtJS 4 to ExtJS 5. Upon testing the index.html, we encountered an error message (displayed in the Firefox-FireBug-console): NetworkError: 404 Not Found - http://localhost:8080/ext/build/e ...

Step-by-step guide on how to showcase elements within v-for by clicking on them

In my data array, only the first element is visible by default. Clicking on either the YES or NO button will display the element with the corresponding id of yes_section or no_section (depending on which button was clicked). For instance, if we click on ...

Conceal social media icons when hovering over specific images similar to the feature on the website medium

I am facing an issue with fading out social links that appear over medium and large images on a webpage. I want the social links to fade out when they are over the images and fade back in once they move off the images. The number of medium and large images ...

Getting request parameters within Model in Loopback can be done by accessing the `ctx`

common/models/event.json { "name": "Event", "mongodb": { "collection": "event" }, "base": "PersistedModel", "idInjection": true, "options": { "validateUpsert": true }, "http": { "path": "organizer/:organizer_id/events" }, "properties": {}, "va ...

Incorporate time zone awareness to JavaScript date objects

Whenever I create objects in my MongoDB using Mongoose, the dates are displayed in the format of, for example, 2016-10-10T15:35:52.764Z (alternatively, it could be yyyy-MM-ddTHH:mm:ssZ). When I utilize Date.now() in JavaScript, I am given a timestamp. Is ...

In Vue JS, what is the best way to update a Child component after clicking a button on the Parent Component?

In my application, I have a setting option that updates from the Parent Component. The setting data is saved in localStorage and three Child Components utilize this setting data. <P> <c1> </c1> <c2> </c2> <c3> < ...

Guide on invoking an ajax function within a for loop

As someone new to ajax and JavaScript, my goal is to call an ajax function multiple times to retrieve specific data from a resource and then store all of that data in an array for later use in my code. Below is the code I have so far: var arr = []; var us ...

Storing the timestamp of when a page is accessed in the database

I am currently working on a PHP website where users can register and access exclusive Powerpoint presentations. The owner has requested that I track the amount of time users spend viewing each presentation, but I am unsure of how to display and record th ...

Obtaining cookies from a separate domain using PHP and JavaScript

Imagine you have a cookie set on first.com, called "user". Now, the goal is to retrieve that cookie on second.com using JavaScript and AJAX. Unfortunately, it's not working as expected and you're receiving xmlHttp.status=0. Here is a sample code ...

Issue with express-validator returning undefined value on forms set to enctype='multipart/form-data'

Currently, I am developing a login authentication application using basic node.js+express. While extracting values (such as name, email, etc) from the registration page, I utilize express-validator for validation. However, I encounter an issue where all va ...