How do I set focus to the first input field when I edit a row in GridView?

Posted on 2006-07-11
Last Modified: 2008-01-09
I want to set focus to the first input field in the row when the user selects "edit". I tried adding:
Control input1 = GridView1.Rows[e.NewEditIndex].Cells[7].Controls[0];
to the Rowediting event handler but this doesn't work because none of the Cells have controls.
So I tried :
but that didn't appear to do anything.
I guess I'm barking up the wrong tree. Any ideas?
Question by:cjmackenzie
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Expert Comment

ID: 17084591

Expert Comment

ID: 17084623
Try using


This should set the focus to the first focasable cell inside that control.

Author Comment

ID: 17084805
I tried that in the RowEditing event handler and the PageLoad event handler without success. Any opther ideas?

Accepted Solution

valrog earned 250 total points
ID: 17084892

Author Comment

ID: 17097873
GridView1.Focus() doesn't work because my text box is not the first focussable cell - both the Sort headings and the Edit buttons can be focussed on too

But your link led me to the solution - I prefer the shorter C# solution to the longer VB solution containing javascript..
I've been trying to access the textbox control in the wrong event - should be on RowDataBinding:    

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState
        & DataControlRowState.Edit) != 0)
            Control c = e.Row.Cells[6].Controls[0];
            //Next line is another way of setting focus

Many thanks



Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
transaction in, sql server 6 46 mvc 2 33
Validating textboxes in red square borders. 2 33
Web page design problem 3 13
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question