如何在< ItemTemplate>中找到控件直放站 [英] How To Find Controls In <ItemTemplate> Repeater

查看:108
本文介绍了如何在< ItemTemplate>中找到控件直放站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此源代码:

<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#代码访问这些控件?

and it's inside an item template tag for an ASP Repeater ... what i want to do is making c# code for some events for these two controls .. the text box and the button ... how can i reach these controls from the c # code ?

推荐答案

您需要挂钩到 OnItemDataBound

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

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

Now, on code behind....

  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 
     }
  }

这篇关于如何在&lt; ItemTemplate&gt;中找到控件直放站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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