为每个不同用户分组中继器
本文关键字:中继器 用户 | 更新日期: 2023-09-27 18:26:25
我有以下中继器项目:
<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;
}
现在,如何将GetManagerUnerifiedLeaveRequests返回的每个不同用户的Repeater项目分组,该请求返回以下方法中的DataTable:
protected void RptLeaveRequests_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (hasRequests)
{
//grouping
}
}
我看到了两种可能的解决方案:
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
}
我更喜欢第二个版本。