从中继器获取复选框对象

编程入门 行业动态 更新时间:2024-10-18 23:25:15
本文介绍了从中继器获取复选框对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个转发器,我试图从LinkBut​​ton事件访问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 } } }

更多推荐

从中继器获取复选框对象

本文发布于:2023-11-25 01:56:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627842.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复选框   对象   中继器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!