嵌套Repeater中内层添加一两行的问题
两层嵌套的Repeater,如图: 外层如“长期激励”、“社保公积金”,内层的就如“股票期权”“养老”等等,这些都能实现,问题是,有些需要加上“单位缴纳”和“个人缴纳”,而有些不需要,这个有什么办法可以实现吗?想了好久,没法子了,特来此求助。望大神们不吝赐教!
粘上代码:前台
<table width="99%" border="0" cellspacing="0" cellpadding="0">
<asp:Repeater ID="rep_Objict" runat="server" OnItemDataBound="rep_Objict_ItemDataBound">
<ItemTemplate>
<tr style="margin: 20px;">
<td style="padding-left: 30px; margin-top: 20px;">
<input type="checkbox" value="<%#Eval("Id")%>" id="parent$<%#Eval("Id") %>" name="ObjectID$<%#Eval("Id") %>" onclick='CheckAll(this)' /><span style="font-size: 16px;"> <%#Eval("Name") %></span>
<ul style="margin-left: 20px;">
<asp:Repeater ID="rep_Property" runat="server">
<ItemTemplate>
<li class="childLi">
<input type="checkbox" value="<%# DataBinder.Eval(((RepeaterItem)Container.Parent.Parent).DataItem, "Id")%>" <%#GetCheckedStateString(Eval("Id").ToString())%> id="child<%#Eval("Id") %>" name="ObjectProID$<%#Eval("Id") %>" /><span class="childDataLable"><%#Eval("Name") %></span></li>
<%# ((Container.ItemIndex+1) %5 == 0 )? "<br />" :""%>
</ItemTemplate>
</asp:Repeater>
</ul>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
<tr>
<td align="center">
<asp:Button ID="btn_SaveAndItemDefine" CssClass="btn btn-success" runat="server"
Text="保存并定义薪资项" OnClick="btn_SaveAndItemDefine_Click" />
</td>
</tr>
</table>
protected void Page_Load(object sender, EventArgs e)在线等 WEB开发,ASP.NET
{
if (!IsPostBack)
{
DataTable dt = BDAService.GetObjectDefine();
rep_Objict.DataSource = dt;
rep_Objict.DataBind();
}
}
protected string GetCheckedStateString(string ObjectPropertyId)
{
string stateString = string.Empty;
if (!string.IsNullOrEmpty(Request.QueryString["Id"]))
{
DataTable dTable = BDAService.GetObjectPropertyId(long.Parse(Request.QueryString["Id"]));
if (dTable.Select("ObjectProID=" + ObjectPropertyId).Count() > 0)
{
stateString = " checked="checked" ";
}
}
return stateString;
}
protected void rep_Objict_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater repProperty =(Repeater)e.Item.FindControl("rep_Property");
//找到分类Repeater关联的数据项
DataRowView rowv = (DataRowView)e.Item.DataItem;
//提取分类ID
int ObgectId = Convert.ToInt32(rowv["Id"]);
DataTable dt = BDAService.GetObjectPropertyDefine(ObgectId);
//根据分类ID查询该分类下的属性,并绑定属性Repeater
repProperty.DataSource = dt;
repProperty.DataBind();
}
}