繁体   English   中英

如何使用转发器的OnItemCommand触发文本框的事件,而不使用LinkBut​​ton?

[英]How to fire event of textbox with OnItemCommand of a repeater , without using LinkButton?

我有一个内部的文本框的中继器,我想,当我从一个文本框移动到另一个文本框,与触发事件OnItemCommand中继器。

<asp:Repeater ID="RptrPeople" runat="server" OnItemDataBound="RptrPeople_ItemDataBound" OnItemCommand="RptrPeople_ItemCommand">
         <ItemTemplate>
                <asp:HiddenField ID="hf" runat="server" Value="<%# Eval(this.ValuedPerson) %>" />
                <asp:TextBox ID="txtDescription" runat="server" IsRequired="false" Visible="true" AutoPostBack="true"  />
         </ItemTemplate>
</asp:Repeater> 

我试图使用文本框的OnTextChanged ,但我无法获得以这种方式触发事件的项目。

在我从一个文本框移动后,使用OnItemCommand (例如,我在Textbox #1输入123 ,然后移动到Textbox #2 ...然后,任何人都可以建议获得触发事件的项目的好方法)我想触发处理具有123值的文本框的事件)?

谢谢

我试图使用文本框的OnTextChanged,但我无法获得以这种方式触发事件的项目。

sender参数始终是触发事件的控件:

protected void txtDescription_TextChanged(Object sender, EventArgs e)
{
    TextBox txtDescription = (TextBox) sender;
}

所以你应该使用它而不是OnItemCommand因为sender是转发器。

如果您还需要获取HiddenField的引用,请使用以下代码:

protected void txtDescription_TextChanged(Object sender, EventArgs e)
{
    TextBox txtDescription = (TextBox) sender;
    var item = (RepeaterItem) txtDescription.NamingContainer;
    HiddenField hf = (HiddenField) item.FindControl("hf");
}

RepeaterItem中任何控件的NamingContainer始终是RepeaterItem 顺便说一句,这与其他web-dataatabound控件(如GridViewDataList的工作方式类似。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM