如何在 AJAX Toolkit 手风琴中动态添加按钮?
How can I dynamically add buttons inside AJAX Toolkit accordion?
感觉这应该很容易,但是在四处寻找了一个完整的工作日之后,我正在寻求一些帮助!我有一个 Web 窗体应用程序,我从 AJAX Control Toolkit (v16.1) 创建了一个手风琴。我后面的代码从输入文件夹中获取文件列表,然后遍历它们。有适当的排序逻辑,但要点是这些文件中的每一个在 6 个预定义的手风琴窗格 Headers 中都有一个适当的位置。内容旨在容纳尽可能多的可点击按钮以满足我的排序逻辑。单击任何按钮时,将调用我的数据库上下文的 get() 方法来填充附近面板中的 GridView。您可以将 Microsoft Outlook 视为示例。电子邮件按日期排序并可单独点击,呈现在附近的视图中。
我的问题是文件当前作为 LiteralControl 输入到手风琴窗格的内容区域中。我正在尝试添加按钮,但我愿意接受其他建议。我只需要 click-ability 这样我就可以适当地填充我的 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>
...
示例 运行 显示 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);
感觉这应该很容易,但是在四处寻找了一个完整的工作日之后,我正在寻求一些帮助!我有一个 Web 窗体应用程序,我从 AJAX Control Toolkit (v16.1) 创建了一个手风琴。我后面的代码从输入文件夹中获取文件列表,然后遍历它们。有适当的排序逻辑,但要点是这些文件中的每一个在 6 个预定义的手风琴窗格 Headers 中都有一个适当的位置。内容旨在容纳尽可能多的可点击按钮以满足我的排序逻辑。单击任何按钮时,将调用我的数据库上下文的 get() 方法来填充附近面板中的 GridView。您可以将 Microsoft Outlook 视为示例。电子邮件按日期排序并可单独点击,呈现在附近的视图中。
我的问题是文件当前作为 LiteralControl 输入到手风琴窗格的内容区域中。我正在尝试添加按钮,但我愿意接受其他建议。我只需要 click-ability 这样我就可以适当地填充我的 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>
...
示例 运行 显示 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);