This is a migrated thread and some comments may be shown as answers.

Auto Focus on TextBox in RadGrid with autogenerated columns

1 Answer 155 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Corey
Top achievements
Rank 1
Corey asked on 30 Aug 2011, 08:09 PM
I'm using the keyboard controls for the RadGrid, however, when i hit enter on a line to edit it, i need it to go to a column that i specify.

The RadGrid has AutoGenerated Columns, and editting is in place.

I've been looking through the forums & KB for the resolution and i see demos and answers if you use an edit form.

I tried to use the following code to set the focus, but the focus isn't really set on the text box, and causes a javascript error when you stop editting.

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item.IsInEditMode)
            {
                string script = String.Format("$get('{0}').focus(); $get('{0}').select();", ((TextBox)e.Item.FindControl("ctl01")).ClientID);
                ScriptManager.RegisterStartupScript(Page, typeof(Page), "myscript", script, true);
            }
        }

1 Answer, 1 is accepted

Sort by
0
Corey
Top achievements
Rank 1
answered on 30 Aug 2011, 08:14 PM
Solved Problem

Added this code

        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                GridEditableItem form = (GridEditableItem)e.Item;
                TextBox dataField = (TextBox)form["Quantity"].Controls[0];
                dataField.Focus();
            }

and put the radgrid into an RadAjaxPanel.
Tags
Grid
Asked by
Corey
Top achievements
Rank 1
Answers by
Corey
Top achievements
Rank 1
Share this question
or