JAN*_*JAN 5 c# asp.net repeater asprepeater visual-studio-2012
我有一个带有文本框的转发器,当我从一个文本框移动到另一个文本框时,我想要发送一个事件,使用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>
Run Code Online (Sandbox Code Playgroud)
我试图使用OnTextChanged文本框,但我不能得到以这种方式触发事件的项目.
任何人都可以请告知一个很好的方式来获取触发事件的项目,之后我从一个文本框移动,使用OnItemCommand (例如,我进123的Textbox #1,然后转移到Textbox #2...然后我想火,是以事件照顾123有价值的文本框)?
谢谢
我尝试使用文本框的 OnTextChanged ,但无法以这种方式获取触发事件的项目。
参数sender始终是触发事件的控件:
protected void txtDescription_TextChanged(Object sender, EventArgs e)
{
TextBox txtDescription = (TextBox) sender;
}
Run Code Online (Sandbox Code Playgroud)
所以你应该使用这个而不是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");
}
Run Code Online (Sandbox Code Playgroud)
NamingContainera 中任何控件的始终RepeaterItem是RepeaterItem。顺便说一句,这对于其他 Web 数据绑定控件(如GridView或 )的工作原理类似DataList。