2017-04-06 98 views
0

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

我的问题是,这些文件目前作为LiteralControl在accordion窗格的Content区域中输入。我试图添加按钮,但我接受其他建议。我只需要点击能力,所以我可以适当地填充我的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需要点击。有任何想法吗?

+1

为什么不使用面板而不是文字并添加按钮或链接?另外在这里我看到你添加文件名作为文字为什么不是一个超链接或按钮?新的LiteralControl(fileInfo.Name.Substring(0,fileInfo.Name.Length - 4) – Krishna

+0

@Krishna,谢谢。我用面板按照你的建议做了这个诀窍。你会正式添加你的答案,以便我可以标记它正确吗?再次感谢! –

回答

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