Wednesday, June 21, 2006
« How smart is the compiler with string li... | Main | Back at the blog. »

Had a customer ask for this functionality. Easily done. I can see using it in most of my GridView applications. You could modify this to recursively move throught e.Controls and find the first TextBox.

protected void GridViewMain_RowDataBound(object sender, GridViewRowEventArgs e) {

    if (e.Row.RowIndex == GridViewMain.EditIndex && e.Row.RowIndex != -1) {

        const string selectScript = "<script language='javascript'>document.getElementById('{0}').select();</script>";

 

        Control control = e.Row.FindControl("TextBoxQuantity");

        if (control != null) {

            Page.ClientScript.RegisterStartupScript(this.GetType(), "FocusEditTextBox", string.Format(selectScript, control.ClientID));

        }

    }

}

 

kick it on DotNetKicks.com   Wednesday, June 21, 2006 7:29:29 PM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [0]  |