C# 如何在AJAX工具包accordion中动态添加按钮?
感觉这应该很容易,但在找了一整天的工作后,我正在寻求帮助!我有一个Web表单应用程序,我从AJAX控件工具包(v16.1)创建了一个手风琴。我的代码隐藏从输入文件夹中获取文件列表,然后对它们进行迭代。有适当的排序逻辑,但要点是这些文件中的每个文件在6个预定义的accordion窗格标题中都有一个适当的位置。内容是为了容纳尽可能多的可点击按钮,以满足我的排序逻辑。单击任何按钮时,将调用my DB context的get()方法来填充附近面板中的GridView。您可以想到Microsoft Outlook,如示例所示。电子邮件按日期排序,可单独单击,并在附近的视图中呈现 我的问题是,这些文件当前作为LiteralControl输入到accordion窗格的内容区域中。我试图添加按钮,但我愿意接受其他建议。我只需要点击功能,这样我就可以适当地填充我的GridView。提前感谢您的帮助,以下是我的一些代码供您思考 Default.aspxC# 如何在AJAX工具包accordion中动态添加按钮?,c#,asp.net,.net,webforms,ajaxcontroltoolkit,C#,Asp.net,.net,Webforms,Ajaxcontroltoolkit,感觉这应该很容易,但在找了一整天的工作后,我正在寻求帮助!我有一个Web表单应用程序,我从AJAX控件工具包(v16.1)创建了一个手风琴。我的代码隐藏从输入文件夹中获取文件列表,然后对它们进行迭代。有适当的排序逻辑,但要点是这些文件中的每个文件在6个预定义的accordion窗格标题中都有一个适当的位置。内容是为了容纳尽可能多的可点击按钮,以满足我的排序逻辑。单击任何按钮时,将调用my DB context的get()方法来填充附近面板中的GridView。您可以想到Microsoft Out
...
<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>
。。。
这两个文件名必须是可单击的。有什么想法吗?尝试添加面板,而不是文字,以便可以在其中添加按钮
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);
为什么不使用面板而不是文字并添加按钮或链接?在这里,我看到您正在添加文件名作为文本,为什么不添加超链接或按钮?新的LiteralControl(fileInfo.Name.Substring(0,fileInfo.Name.Length-4)@Krishna,谢谢。我按照你的建议使用了面板,这就成功了。你能正式添加你的答案吗?这样我就可以把它标记为正确了?再次感谢!
...
<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>
...
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);