如何在AJAX Toolkit手风琴中动态添加按钮?

时间:2017-04-06 17:47:49

标签: c# asp.net .net webforms ajaxcontroltoolkit

这样的感觉应该很容易,但在环顾四周,我寻求一些帮助!我有一个Web Forms应用程序,我从AJAX Control Toolkit(v16.1)创建了一个手风琴。我的代码后面从输入文件夹中获取文件列表,然后遍历它们。有适当的排序逻辑,但要点是这些文件中的每一个都有6个预定义的折叠窗格标题中的适当位置。内容旨在容纳尽可能多的可点击按钮,以满足我的排序逻辑。单击任何按钮时,将调用我的DB上下文的get()方法以填充附近面板中的GridView。您可以考虑Microsoft Outlook,例如。电子邮件按日期排序,可单独点击,在附近的视图中呈现。

我的问题是这些文件目前在手风琴窗格的“内容”区域中作为LiteralControl输入。我试图添加按钮,但我可以接受其他建议。我只需要点击能力,所以我可以适当地填充我的GridView。在此先感谢您的帮助,以下是我的一些思考代码...

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>

...

示例运行显示其中一个面板

enter image description here

这两个文件名需要是可点击的。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

尝试添加面板而不是文字,以便您可以在其中添加按钮。

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);