2013-08-05 10 views
0

我有以下的repeater項目:組轉發器爲每個不同的用戶

<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> 

在頁面加載我綁定的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返回一個DataTable的方法如下:

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

你是什麼意思的分組? –

+0

每個不同用戶的組數據。例如,用戶可以有多個請假請求,從而顯示用戶的姓名,並在其下面顯示用戶提出的所有請求,類似於此,但不是Ticker01和02,我需要用戶名:http://aspnettuts.files .wordpress.com/2010/10/repeater-group.gif?w = 595 – user1986761

+0

這裏有一個幾乎完全相同的完整示例:http://stackoverflow.com/questions/11653190/grouped-gridview-with-expandable-groups/11657327#11657327 – Icarus

回答

1

I看到兩個可能的解決方案:

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 
} 

我寧願第二個版本。

相關問題