gpt4 book ai didi

c# - Repeater 中的项目符号列表

转载 作者:太空宇宙 更新时间:2023-11-03 13:37:47 24 4
gpt4 key购买 nike

我在数据库中有 2 个表是连接的

tblPackage
id Name
1 Package A
2 Package B

tblDetails
id PackageID Details
1 1 PackageDetails11
2 1 PackageDetails12
3 1 PackageDetails13
4 1 PackageDetails14
5 2 PackageDetails21
6 2 PackageDetails22
7 2 PackageDetails23

现在我想让它在中继器上操纵它

HTML

<asp:Repeater ID="rptrPackage" runat="server">
<ItemTemplate>
<asp:Label id="Pack" runat="server" Text='<%# Bind("Pack") %>'></asp:Label>
<asp:BulletedList id="Details" runat="server">
</asp:BulletedList>
</ItemTemplate>
</asp:Repeater>

ASP

private void Populate()
{
DataTable dtPackage = tblPackage();
DataTable dtDetails = tblDetails();

rptrPackage.DataSource = dtPackage;
rptrPackage.DataBind();
}

最佳答案

试试这个

aspx

    <asp:Repeater ID="rptrPackage" runat="server">
<ItemTemplate>
<asp:Label ID="Pack" runat="server" Text='<%# Bind("Pack") %>'></asp:Label>
<asp:HiddenField ID="hID" Value='<%# Eval("PackageID") %>' runat="server" />
<asp:Repeater runat="server" ID="rptDetails">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<%# Eval("Details")%>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>

代码隐藏

    private void Populate()
{
DataTable dtPackage = tblPackage();
DataTable dtDetails = tblDetails();

rptrPackage.DataSource = dtPackage;
rptrPackage.DataBind();

foreach (RepeaterItem item in rptrPackage.Items)
{
Repeater rptDetails = ((Repeater)item.FindControl("rptDetails"));
rptDetails.DataSource = dtDetails.Select("PackageID = " + ((HiddenField)item.FindControl("hID")).Value).CopyToDataTable();
rptDetails.DataBind();
}
}

关于c# - Repeater 中的项目符号列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18158783/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com