本文主要是介绍repeater嵌套Repeater绑定List泛型对象,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
之前在网上找Repeater嵌套,大多都是绑定的DATASET或者是datatable,很少有绑定List泛型对象。为啦找到解决办法,苦闷啦好一阵子。现在解决啦,和大家分享一下。
这是嵌套运行效果
这是前台页面
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div class="main">
<div class="container">
<div class="containerheader">
<div class="headleft">
<p>
单页/海报
</p>
</div>
<div class="headright">
</div>
</div>
<div class="sidebar">
<uc:Sidebar ID="Sidebar" runat="server" />
</div>
<div class="content">
<div class="contenttop">
<div id="Main">
<div class="contenttop">
<ul>
<li>
<%-- 成品尺寸等的repeater--%>
<asp:Repeater ID="reProductpartItemList" runat="server">
<ItemTemplate>
<p>
<a><span>
<%#((DscyModel.ProductPartParameter)Container.DataItem).ParameterName%></span></a>
<img src="../b_Images/help.png" alt="help" title="" rel="Tooltip" /></p>
</ItemTemplate>
</asp:Repeater>
<p>
<a><span>工艺类型</span></a><img src="../b_Images/help.png" alt="help" title="工艺类型" rel="Tooltip" />
</p>
</li>
</ul>
</div>
<div class="clear">
</div>
<div class="autodiv">
</div>
<div class="contentmain">
<%-- 通过repeater嵌套,显示成品尺寸,p面下的具体大小等--%>
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound" OnItemCreated="Repeater1_ItemCreated">
<ItemTemplate>
<div class="attribute_list">
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
<div class="attribute_list_option">
<a href="javascript:void(0)">
<%# DataBinder.Eval(Container.DataItem, "ItemName") %>
<%-- <%#((DscyModel.ProductPartParameter)Container.DataItem).ParameterName%>--%>
</a>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</ItemTemplate>
</asp:Repeater>
<div class="attribute_list">
<%-- 显示 工艺类型的具体内容--%>
<asp:Repeater ID="reProductpartprocess" runat="server">
<ItemTemplate>
<div class="attribute_list_option">
<a href="javascript:void(0)">
<%# DataBinder.Eval(Container.DataItem, "ProcessName")%></a>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</div>
</div>
</div>
<div class="clear">
</div>
</div>
<div class="clear">
</div>
<div class="soliddiv">
</div>
</div>
</asp:Content>
这是后台的代码
int prodcutid = 0;//这个全局变量的id是定义好的。直接通过页面传值的
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
prodcutid = Convert.ToInt32(Request["ProId"]);
//部件参数(成品尺寸,P面)的repeater
gProductpartparamsList(prodcutid);
//部件子表(成品尺寸的高宽等)
gProductpartItemList(prodcutid);
//部件工艺类型
gProductpartprocessList(prodcutid);
GetPartProcessFromInfo(prodcutid);
}
}
/// <summary>
/// 查看主表信息的时候,部件表 工艺表对应的信息都需要显示
/// </summary>
/// <param name="prodcutid"></param>
private void GetPartProcessFromInfo(int prodcutid)
{
List<ProductPartParameter> productpart = (new ProductInFoBLL()).GetProductPartParmList(prodcutid);
reProductpartItemList.DataSource = productpart;
reProductpartItemList.DataBind();
}
/// <summary>
/// 取对应产品部件的元素(部件参数,eg:成品尺寸,p/面)
/// </summary>
/// <param name="partItemId"></param>
/// <returns></returns>
public void gProductpartparamsList(int partItemId)
{
//通过调用GetProductPartParmList方法,deng
List<ProductPartParameter> productpart = (new ProductInFoBLL()).GetProductPartParmList(partItemId);
reProductpartItemList.DataSource = productpart;
reProductpartItemList.DataBind();
}
/// <summary>
/// 取对应产品部件的元素(部件参数,eg:成品尺寸的长宽高)
/// </summary>
/// <param name="partId"></param>
public void gProductpartItemList(int partId)
{
List<ProductPartParameter> productpart = (new ProductInFoBLL()).GetProductPartParmList(prodcutid);
Repeater1.DataSource = productpart;
Repeater1.DataBind();
}
/// <summary>
/// 这个事件是当repeater绑定一列后执行一次,绑定一列执行一次
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//判断里层repeater处于外层repeater的哪个位置( AlternatingItemTemplate,FooterTemplate,
//HeaderTemplate,,ItemTemplate,SeparatorTemplate)
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rep = e.Item.FindControl("Repeater2") as Repeater;//找到里层的repeater对象
ProductPartParameter Idparam = (ProductPartParameter)e.Item.DataItem;
int typeid = Convert.ToInt32(Idparam.ID_Parameter);
List<ProductPartParameterItem> productpartParaItem = (new ProductInFoBLL()).GetProductPartItemList01(prodcutid, typeid);
rep.DataSource = productpartParaItem;
rep.DataBind();
}
}
/// <summary>
/// 在r1的ItemCreated事件中注册一下r2
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Repeater1_ItemCreated(object sender, RepeaterItemEventArgs e)
{
Repeater rep = e.Item.FindControl("Repeater2") as Repeater;
}
//取对应部件工艺可选参数列表
public void gProductpartprocessList(int partId)
{
List<ProductPartProcess> productpartprocess = (new ProductInFoBLL()).GetProductPartItemProcessList(partId);
reProductpartprocess.DataSource = productpartprocess;
reProductpartprocess.DataBind();
}
这篇关于repeater嵌套Repeater绑定List泛型对象的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!