“收割者”中的项目符号列表

本文关键字:收割者 符号 列表 项目 | 更新日期: 2023-09-27 18:27:02

我在数据库中有两个表w/c连接

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

在中继器内使用SqlDataSourse

<asp:Repeater ID="rptrPackage" runat="server" >
<ItemTemplate>
<asp:HiddenField ID="PackID" runat="server"  Value='<%# Eval("id") %>' 
/>
<asp:Label id="Pack" runat="server" Text='<%# Eval("Name") %>'></asp:Label><br/>
<asp:BulletedList ID="Details" runat="server"   
        DataSourceID="SqlDataSource1" DataTextField="Details"   
        DataValueField="id">
        </asp:BulletedList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"    ConnectionString="<%$ ConnectionStrings:YourConnectionString %>" 
    SelectCommand="SELECT * FROM [tblDetail] WHERE [PackageID] = @PID"  >
    <SelectParameters>
        <asp:ControlParameter    Name="PID"   Type="Int32"  ControlID="PackID"   PropertyName="Value" />
     </SelectParameters>
 </asp:SqlDataSource>
 </ItemTemplate>
</asp:Repeater>