如何找到能够控制在 中继器(How To Find Controls In

2019-09-17 04:22发布

我有这样的源代码:

<div id = "AddComment">
    <asp:TextBox ID="txtComment" runat="server" TextMode="MultiLine" Height="20"></asp:TextBox>
    <asp:Button ID="btnComment" CommandName="btnComment_click"  runat="server" Text="Comment" />                           
</div>

并且它是一个ASP直放站项目模板标签内...我想要做的是使一些事件这两个控件的C#代码..文本框和按钮...我怎样才能从C到这些控件#代码?

Answer 1:

您需要挂钩到OnItemDataBound

<asp:Repeater OnItemDataBound="RepeaterItemEventHandler" ... />

现在,在后面的代码....

  void RepeaterItemEventHandler(Object Sender, RepeaterItemEventArgs e) {
     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
        TextBox currentTextBox = (TextBox)e.Item.FindControl("txtComment");
        //do something cool 
     }
  }


文章来源: How To Find Controls In Repeater