码迷,mamicode.com
首页 > Web开发 > 详细

asp:Repeater实例备忘

时间:2016-09-01 09:16:31      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

 

1.前置部分

<asp:Repeater ID="rptPlanNo" runat="server" OnItemDataBound="rptPlanNo_ItemDataBound">
         <ItemTemplate>
                   <asp:CheckBox ID="cb" runat="server" />
         </ItemTemplate>
 </asp:Repeater>

2.1后置代码的数据绑定部分

protected void dplType_SelectedIndexChanged(object sender, EventArgs e)
{
   //......
   List<PlanNo_Generated_DistributeEntity> list = dal.GetAll(parms, "Id", 30, 0, out recordCount);//30表示控制每次派发个数
   rptPlanNo.DataSource = list;
   rptPlanNo.DataBind();
}

2.2在绑定Repeater时,怎样拿到ItemTemplate中的asp:CheckBox,并且取得绑定的数据项,如这里的PlanNo_Generated_DistributeEntity

protected void rptPlanNo_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
   if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
   {
       PlanNo_Generated_DistributeEntity entity = e.Item.DataItem as PlanNo_Generated_DistributeEntity;
       CheckBox check = e.Item.FindControl("cb") as CheckBox;
       check.Text = entity.Plan_No;
   }
}

2.3 在提交时,怎样取得ItemTemplate中的asp:CheckBox

protected void btnSendPlanNo_Click(object sender, EventArgs e)
{
   //....
   foreach (Control c in this.rptPlanNo.Controls)
   {
       CheckBox cbx = (CheckBox)c.FindControl("cb");
       if (cbx != null)
       {
           if (cbx.Checked == true)
           {
               entity.Plan_No =  cbx.Text;
               //....
           }
       }
   }
}        

 

asp:Repeater实例备忘

标签:

原文地址:http://www.cnblogs.com/zhuji/p/5828306.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!