asp:Repeater实例备忘
Posted 轴轴
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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实例备忘的主要内容,如果未能解决你的问题,请参考以下文章