2017-04-06 101 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);