本文介绍了从中继器获取复选框对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个转发器,我试图从LinkButton事件访问Checkbox控制器。Repeater控件仅包含文字和链接按钮,但不包含复选框控件。
I have a repeater and I am trying to access the Checkbox controller from the LinkButton event.The Repeater controls only contain the literals and linkbuttons but not checkbox controls.
<asp:Repeater ID="rptTicketsInPerformance" OnItemDataBound="rptTicketsInPerformance_ItemBound" runat="server"> <ItemTemplate> <asp:CheckBox ID="cbticketSelect" runat="server" /> <asp:Literal ID="ltticketDescription" runat="server" /> </ItemTemplate> <FooterTemplate> <div class="change-buttons"> <asp:LinkButton ID="btDonate" runat="server" CssClass="button-primary" Text="Donate" OnClick="donateButton_click" /> <asp:HyperLink ID="hlCancel" runat="server" CssClass="button-primary close-reveal-modal" Text="Cancel" /> </div> </FooterTemplate> </asp:Repeater>隐藏代码
protected void donateButton_click(object sender, System.EventArgs e) { RepeaterItem items = ((sender as LinkButton).Parent as RepeaterItem); foreach(var itm in items.Controls) { if(itm is CheckBox) { // Do something here } } }推荐答案
尝试以下操作 FindControl :
protected void donateButton_click(object sender, System.EventArgs e) { RepeaterItem items = ((sender as LinkButton).Parent as RepeaterItem); foreach (RepeaterItem itm in items.Controls) { CheckBox chk = (CheckBox)itm.FindControl("cbticketSelect"); if (chk.Checked) { Lable1.Text = "Do something "; // Do something here } } }更多推荐
从中继器获取复选框对象
发布评论