大家好,又见面了,我是你们的朋友全栈君。
前台代码:
<asp:Repeater ID="rptList" runat="server" OnItemDataBound="users_list">
<HeaderTemplate>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="ltable">
<thead>
<tr>
<th style="width: 80px;">
主表字段
</th>
<th style="width: 320px;">
<table width="100%" border="0" cellpadding="5" cellspacing="1">
<tr bgcolor="#FFFFFF">
<th width="50%">
<div align="center">
<font>对应字段1</font></div>
</th>
<th width="50%">
<div align="center">
<font>对应字段1</font></div>
</th>
</tr>
</table>
</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="users_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)
{
BLL.xs_user bll = new BLL.xs_user();
this.rptList.DataSource = bll.GetList(this.pageSize, this.page, _strWhere, _orderby, out this.totalCount, "manager_qualification_certificate");
this.rptList.DataBind();
}
//副表数据绑定
protected void users_list(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("users_list");//找到要绑定数据的Repeater
//Literal Lit = ((Literal)e.Item.FindControl("Lit_cn"));
//Literal Lit_remark = ((Literal)e.Item.FindControl("Lit_remark"));
if (repeater!= null)
{
DataTable dt = 获取到的数据;
//string remark = "";
//foreach (DataRow item in dt.Rows)
//{
// if (!string.IsNullOrWhiteSpace(item["u_remark"].ToString()))
// {
// remark += item["name"].ToString() + ":" + item["u_remark"].ToString() + "。";
// }
//}
//Lit_remark.Text = remark + Lit_remark.Text;
repeater.DataSource = dt;
repeater.DataBind();
}
}
}
共同学习,一起进步,有些东西我也不懂,可以大家一起讨论!
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/159112.html原文链接:https://javaforall.cn