开发者

Bind OnTextChanged Event TextBox inside Gridview inside Update Panel

开发者 https://www.devze.com 2023-04-03 23:06 出处:网络
I have a GridView containing a TextBox in <asp:TemplateField /> and The GridView is residing inside an AJAX 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);
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消