Go Premium for a chance to win a PS4. Enter to Win


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

Posted on 2006-07-11
Medium Priority
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
  • 3
  • 2

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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

926 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