Bind OnTextChanged Event TextBox inside Gridview inside Update Panel
I have a GridView containing a TextBox in <asp:TemplateField /> and The GridView is residing inside an AJAX Update Panel.
I want to register the TextChanged Event for the textbox inside the GridView but only for the first row inside the Grid.
Is there a way to do it?
I tried binding the OnTextChangedEvent and AutoPostBack = true for TextBox, but it is firing for textbox in each row. How can 开发者_StackOverflow中文版I limit that TextChanged Event to only the TextBox in first row in the GridView.
Can you please help me.
Thanks and appreciate your feedback.
Perhaps you can use GridView_RowDataBound event and instead of attaching event to TextBox in aspx markup, do it via code behind:
protected void view_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowIndex == 0)
{
TextBox txtBox = (TextBox)e.Row.FindControl("txtBoxId");
txtBox.TextChanged += new EventHandler(txtBox_TextChanged);
}
}
}
加载中,请稍侯......
精彩评论