0

Feels like this should be easy, but after looking around for a full work day, I'm seeking some help! I have a Web Forms app and I created an accordion from the AJAX Control Toolkit (v16.1). My code behind gets a list of files from an input folder and then iterates through them. There is sorting logic in place, but the gist is that each of these files has a proper place among 6 predefined accordion pane Headers. The Content is meant to house as many clickable buttons as necessary to satisfy my sorting logic. When any button is clicked, the get() method of my DB context is invoked to populate a GridView in a nearby panel. You can think of Microsoft Outlook, as in example. Emails are sorted by date and individually clickable, which render in a nearby view.

My issue is that the files are currently entered as a LiteralControl in the Content area of the accordion pane. I'm trying to add buttons instead, but I'm open to other suggestions. I just need click-ability so I can populate my GridView appropriately. Thanks in advance for your help, and here is some of my code to ponder over...

Default.aspx

...

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
    <asp:GridView ID="TransactionGridView" runat="server" DataSourceID="TransactionODS" CellPadding="4" ForeColor="#333333" GridLines="None" >
        <AlternatingRowStyle BackColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <FooterStyle BackColor="#5078B3" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5078B3" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#D3DEEF" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F5F7FB" />
        <SortedAscendingHeaderStyle BackColor="#6D95E1" />
        <SortedDescendingCellStyle BackColor="#E9EBEF" />
        <SortedDescendingHeaderStyle BackColor="#4870BE" />
    </asp:GridView>
    <asp:ObjectDataSource ID="TransactionODS" runat="server" SelectMethod="GetTransactionSet" TypeName="ZipApprove.Models.TransactionRepository"></asp:ObjectDataSource>
</asp:Content>

<asp:Content ID="HistoryNavigationContent" ContentPlaceHolderID="NavigationPanel" runat="server">
    <ajaxToolkit:Accordion
        ID="HistoryAccordion"
        runat="server"
        SelectedIndex="0"
        HeaderCssClass="accordionHeader"
        HeaderSelectedCssClass="accordionHeaderSelected"
        ContentCssClass="accordionContent"
        AutoSize="None"
        Height="450"
        FadeTransitions="true"
        TransitionDuration="250"
        FramesPerSecond="40"
        RequireOpenedPane="false"
        SuppressHeaderPostbacks="true">
        <Panes></Panes>
        <HeaderTemplate></HeaderTemplate>
        <ContentTemplate></ContentTemplate>
    </ajaxToolkit:Accordion>
</asp:Content>

Default.aspx.cs

public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var files = 
                Directory.GetFiles(
                    Server.MapPath("Output_Files"), 
                    "*.*", 
                    SearchOption.AllDirectories
                );

            // Create the date panes and give them a header

...
            AccordionPane lastWeek = new AccordionPane();
                lastWeek.HeaderContainer.Controls
                    .Add(new LiteralControl("A Week Ago"));

...

            foreach (var file in files)
            {
                var fileInfo = new FileInfo(file);                

                if (fileInfo.Extension == ".csv")
                {
                    string fileDTString = 
                        fileInfo.Name.Substring(
                            fileInfo.Name.Length - 16, 
                            12
                        );
                    DateTime dateTime = 
                        DateTime.ParseExact(
                            fileDTString, 
                            "MMddyyyyHHmm", 
                            CultureInfo.InvariantCulture
                        );

...

                    else if (
                        dateTime >= 
                            DateTime.Now
                            .AddDays(-7)
                            .AddHours(-DateTime.Now.Hour)
                            .AddMinutes(-DateTime.Now.Minute) && 
                        dateTime < 
                            DateTime.Now
                                .AddDays(-1)
                                .AddHours(-DateTime.Now.Hour)
                                .AddMinutes(-DateTime.Now.Minute)
                    )
                    {
                        // Parsed between 1 week ago at midnight and up to, not
                        // including, midnight of the case above                        
                        lastWeek.ContentContainer.Controls.Add(
                            new LiteralControl(
                                fileInfo.Name.Substring(
                                    0, fileInfo.Name.Length - 4
                                )
                            )
                        );
                        lastWeek.ContentContainer.Controls.Add(
                            new Literal()
                            {
                                Mode = LiteralMode.PassThrough,
                                Text = "<br/><br/>"
                            }
                        );
                    }
                    else if (

...

                } // End of CSV "If"
            } // End of looping through files

...

            HistoryAccordion.Panes.Add(lastWeek);

...

        } // End of Page Load method
    } // End of class
} // End of namespace

Site.Master*

...

<div id="panelsDiv" style="display:flex">
    <div
        ID="NavigationPanelContainer"
        style="
            margin: 5px 5px 5px 5px; 
            width: 250px; 
            overflow-y: auto; 
            color: black; 
            height: 500px">
        <asp:ContentPlaceHolder ID="NavigationPanel" runat="server"></asp:ContentPlaceHolder>
    </div>
    <div class="container body-content" 
        ID="ContentPanelContainer"
        style="
            flex: 1; 
            height: 500px; 
            margin: 5px 5px 5px 5px; 
            overflow-y: auto;">
        <asp:ContentPlaceHolder ID="MainContent" runat="server" />
    </div>
</div>

...

Example run showing 1 of the panels

enter image description here

Those two filenames need to be clickable. Any ideas?

midoriha_senpai
  • 177
  • 1
  • 16
  • 1
    Why don't you use a panel instead of literal and add buttons or links ? Also here I see you are adding file name as literal why not a hyperlink or button ? new LiteralControl(fileInfo.Name.Substring(0, fileInfo.Name.Length - 4 ) – Krishna Apr 06 '17 at 17:56
  • @Krishna, thank you. I used panels as you suggested and that did the trick. Will you add your answer officially so that I can mark it as correct? Thanks again! – midoriha_senpai Apr 18 '17 at 23:00

1 Answers1

1

Try adding panels instead of Literals so that you can add buttons in it.

Panel pnl = new Panel();
LinkButton lnkbtnFile = new LinkButton();
lnkbtnFile.Text = "A Week Ago";
pnl.Controls.Add(lnkbtnFile);
AccordionPane lastWeek = new AccordionPane();
                lastWeek.HeaderContainer.Controls
                    .Add(pnl);
Krishna
  • 1,945
  • 1
  • 13
  • 24