0

我有以下中继器项目:

<asp:Repeater ID="RptLeaveRequests" runat="server" 
        onitemdatabound="RptLeaveRequests_ItemDataBound">
<ItemTemplate>
    <table id="tableItem" runat="server">
        <tr>
                <td style="width: 100px;">
                    <asp:Label ID="lblDate" runat="server" Text='<%#Eval("Date", "{0:dd/M/yyyy}") %>'></asp:Label>
                </td>
                <td style="width: 100px;">
                    <asp:Label ID="lblHours" runat="server" Text='<%#Eval("Hours") %>'></asp:Label>
                </td>
                <td style="width: 200px;">
                    <asp:Label ID="lblPeriod" runat="server" Text='<%#Eval("AMorPM") %>'></asp:Label>
                </td>
                <td style="width: 200px; font-size:10px;">
                    <asp:Label ID="lblNote" runat="server" Text='<%#Eval("Note") %>'></asp:Label>
                </td>
                <td style="50px">
                    <asp:RadioButtonList ID="rbtVerified" runat="server" >
                        <asp:ListItem Value="1">Accept</asp:ListItem>
                        <asp:ListItem Value="2">Reject</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
                <td>
                    <asp:TextBox ID="txtNotes" runat="server" ></asp:TextBox>
                </td>
            </tr>
    </table>
</ItemTemplate>
</asp:Repeater>

在页面加载时,我正在绑定中继器

else if(Convert.ToInt32(Session["UserLevel"]) != 0 && Convert.ToInt32(Session["UserLevel"]) < 151)
{
       RptLeaveRequests.DataSource = newLeaveLogic().GetManagerUnverifiedLeaveRequests(Convert.ToInt32(Context.User.Identity.Name));
        RptLeaveRequests.DataBind();
        hasRequests = true;
}

现在,如何为 GetManagerUnferifiedLeaveRequests 返回的每个不同用户分组 Repeater 项,GetManagerUnferifiedLeaveRequests 在下面的方法中返回一个 DataTable:

protected void RptLeaveRequests_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
       if (hasRequests)
       {
             //grouping
       }
}
4

1 回答 1

1

我看到两种可能的解决方案:

1)使用嵌套中继器:

<asp:Repeater ID="RptGroups" runat="server" onitemdatabound="RptGroups_ItemDataBound">
    <ItemTemplate>
        <asp:Repeater ID="RptLeaveRequests" runat="server"  onitemdatabound="RptLeaveRequests_ItemDataBound">
            <ItemTemplate>
                ...
            </ItemTemplate>
        </asp:Repeater>
    </ItemTemplate>
</asp:Repeater>

2)对组使用单个转发器,并使用例如DataList或其他控件来呈现每个组以用于项目列表。

在这种情况下,您可以在此处将组列表绑定到数据源:

 RptLeaveRequests.DataSource = itemsGroups;
 RptLeaveRequests.DataBind();

并在此处绑定组项列表:

protected void RptLeaveRequests_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
      //bind here list of group items
}

我更喜欢第二个版本。

于 2013-08-05T13:27:59.710 回答