RadGrid Inline Add - Default Focus

4 posts, 0 answers
  1. Mike
    Mike avatar
    11 posts
    Member since:
    Jun 2012

    Posted 10 Apr 2012 Link to this post

    My customer would like the default focus set so when they click the add new record button the focus is set to the first textbox on the input line so they can begin typing without having to click the field first. Is this possible? I don't see any settings that would suggest so. Perhaps a sneaky code behind trick? Any tips greatly appreciated.

    ~Mike
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 10 Apr 2012 Link to this post

    Hello Mike,

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            
                GridEditableItem item = e.Item as GridEditableItem;
      
                // bound column
                (item["ID"].Controls[0] as TextBox).Focus();
      
                //textbox control in edititemtemplate in template column
                (item.FindControl("txtparent") as TextBox).Focus();
            }
    }


    Thanks,
    Jayesh Goyani
  3. Mike
    Mike avatar
    11 posts
    Member since:
    Jun 2012

    Posted 10 Apr 2012 Link to this post

    Thank you! Worked great!
  4. Swati
    Swati avatar
    7 posts
    Member since:
    Jan 2017

    Posted 26 Sep 2017 Link to this post

    Hello jayesh,

    I have same requirement as mentioned by Mike.  But this code dont work completely for me.

    I am able to set focus  to editable textbox in-line but later immediately focus gets changed to Filter control upwards in same column. Any help for this please?

Back to Top