萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> asp.net編程 >> ASP.Net中數據展示控件的嵌套使用示例

ASP.Net中數據展示控件的嵌套使用示例

 1,工作中遇到這樣一個需求,頁面上要把所有的User加載出來,同時每個User後面緊跟著要把User的任務加載出來!我的處理方法是用Repeater來加載所有的User,同時在Repeater裡面嵌套一個GridView,將每個User的任務展示出來!代碼如下

前台代碼:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 <asp:Repeater ID="Repeater1" runat="server"  onitemdatabound="Repeater1_ItemDataBound"> <HeaderTemplate> <table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr> </HeaderTemplate> <ItemTemplate> <td class="list_table_in">    <span class="leaderTitle">高管:<a href='/LeaderSchedule/_layouts/LS/LeaderDetail.aspx?loginName=<%#Eval("LoginName") %>'><%#Eval("UserName") %></a></span><asp:GridView ID="gv_InRep" runat="server" AutoGenerateColumns="False" AllowSorting="True" OnRowCreated="GV_DoneList_RowCreated" OnSorting="GV_DoneList_Sorting" AllowPaging="True" CssClass="tasklisttbl" Width="100%" OnRowDataBound="GV_DoneList_RowDataBound" EnableModelValidation="True"> <AlternatingRowStyle BackColor="#FDFEFF" /> <HeaderStyle HorizontalAlign="Center" ForeColor="Black" Height="20" /> <RowStyle HorizontalAlign="Center" Height="26px" /> <Columns> <asp:BoundField HeaderText="日期" ItemStyle-CssClass="custom" DataField="Date" SortExpression="Date"> <ItemStyle Width="15%" /> </asp:BoundField> <asp:BoundField HeaderText="時間" DataField="Time" SortExpression="Time"> <ItemStyle Width="11%" /> </asp:BoundField> <asp:BoundField HeaderText="工作安排" DataField="WorkPlan" SortExpression="WorkPlan"> <ItemStyle Width="11%" /> </asp:BoundField> <asp:BoundField HeaderText="地點" DataField="Place" SortExpression="Place"> <ItemStyle Width="11%" /> </asp:BoundField> </Columns> <PagerTemplate> </PagerTemplate> </asp:GridView> </td> <asp:Literal ID="Literal1" runat="server" Text='<%#Eval("Flag") %>'></asp:Literal> </ItemTemplate> <FooterTemplate> </tr></table> </FooterTemplate> </asp:Repeater>

後台代碼:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { try { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { GridView gv = e.Item.FindControl("gv_InRep") as GridView;//找到裡層的repeater對象 Leader rowv = (Leader)e.Item.DataItem;//找到分類Repeater關聯的數據項  string typeid = rowv.LoginName; //獲取填充子類的id  SetSorting(); gv.DataSource = PointDataSource(typeid); gv.DataBind();    } }    catch (Exception ex) {    SysLog syslog = new SysLog(); syslog.ListName = ConstData.ListName_PCITC_LS_Schedule; syslog.LType = "Repeater的Item綁定事件異常"; syslog.WorkFlowName = "領導日程管理系統"; syslog.Location = "Repeater綁定數據:OtherSchedule.aspx"; syslog.Message = "頁面信息加載異常:" + ex.Message; syslog.DataSource = 0; logprovider.AddAuditRecordToSource(syslog); } }
copyright © 萬盛學電腦網 all rights reserved