简体   繁体   English

如何在onBlur事件上进行ASP.Net GridView回发?

[英]How do I make an ASP.Net GridView postback on an onBlur event?

I have an ASP.Net GridView, with two columns ("ID" and "name"). 我有一个ASP.Net GridView,有两列(“ ID”和“ name”)。 The name column is editable via an <asp:TextBox>. 名称列可通过<asp:TextBox>编辑。 What I want to do is have the grid trigger its update event when the user clicks away from an editable cell. 我想做的是,当用户单击可编辑单元格以外的位置时,让网格触发其更新事件。

I know I can attach an onBlur event handler to the TextBox to retrieve the value when the user clicks away. 我知道我可以将onBlur事件处理程序附加到TextBox以在用户单击时检索值。 However, I don't know how to trigger the GridView's update event programmatically through JavaScript. 但是,我不知道如何通过JavaScript以编程方式触发GridView的更新事件。 Any suggestions? 有什么建议么?

On your TextBox set AutoPostBack="True" . 在您的TextBox设置AutoPostBack="True" This will cause a postback when the client change event fires, which is probably what you want rather than blur . 当客户端change事件触发时,这将导致回发,这可能是您想要的而不是blur Attach a TextChanged handler to the textbox and you can call your grid update method from there. TextChanged处理程序附加到文本框,然后可以从此处调用网格更新方法。

you can get the row index for the textbox that triggered the event like this: 您可以像这样触发事件的文本框获取行索引:

protected void TextBox2_TextChanged(object sender, EventArgs e)
{
    GridViewRow gridRow = ((GridViewRow)((TextBox)sender).NamingContainer);
    Console.WriteLine(gridRow.RowIndex);
}

您可以通过onBlur事件为Form对象调用Submit方法。

myForm.submit();

您可以在文本框上设置AutoPostback =“ True”,然后在Codebehind中将新值保存在事件处理程序中。

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

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