首页 > 代码库 > asp:Repeater实例备忘
asp:Repeater实例备忘
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实例备忘
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。