Reputation: 479
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 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.
Upvotes: 1
Views: 6040
Reputation: 6802
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);
}
}
}
Upvotes: 2