<asp:Repeater ID="rptList" runat="server" OnItemDataBound="Getdata"> <HeaderTemplate> <table width="100%" border="0" cellspacing="0" cellpadding="0" c ...
<asp:Repeater ID="rptList" runat="server" OnItemDataBound="Getdata"> <HeaderTemplate> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="ltable"> <thead> <tr> <th style="width: 80px;"> 主表欄位名 </th>
<th>
子集
</th> <th style="width: 100px;"> <i class="iconfont icon-setting bigger"></i>操作 </th> </tr> </thead> </HeaderTemplate> <ItemTemplate> <tr> <td> 主表欄位 </td> <td> <table width="100%" border="0"> <asp:Repeater ID="data_list" runat="server"> <ItemTemplate> <tr bgcolor="#FFFFFF"> <td width="50%" align="center"> 子表對應數據1 </td> <td width="50%" align="center"> 子表對應數據2 </td> </tr> </ItemTemplate> </asp:Repeater> </table> </td> <td> <a href="#">修改</a> <a href="#">查看</a> </td> </tr> </ItemTemplate> <FooterTemplate> <%#rptList.Items.Count == 0 ? "<tr><td align=\"center\" colspan=\"3\"><font color=\"#F89406\">暫無記錄</font></td></tr>" : ""%> </table> </FooterTemplate> </asp:Repeater>
前臺代碼:
//主表數據綁定 private void RptBind(string _strWhere, string _orderby) {this.rptList.DataSource =dt; this.rptList.DataBind(); } //副表數據綁定 protected void Getdata(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { string ID = ((DataRowView)e.Item.DataItem).Row["ID"].ToString();//獲得對應ID Repeater repeater= (Repeater)e.Item.FindControl("data_list");//找到要綁定數據的Repeater //Literal Lit = ((Literal)e.Item.FindControl("Lit_cn")); if (repeater!= null) { repeater.DataSource = dt; repeater.DataBind(); } } }
後臺代碼
很久以前的東西了,新同事要用到,就拿出來整理下