从中继器获取复选框对象 [英] Get Checkbox Object from a Repeater

查看:135
本文介绍了从中继器获取复选框对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个转发器,我试图从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
        }
    }
}

这篇关于从中继器获取复选框对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆