Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

asp.net gridview focus on 2nd column of edited row

Posted on 2012-08-10
11
Medium Priority
?
1,026 Views
Last Modified: 2012-08-17
I'm trying to focus on the 2nd cell of the top row I just inserted.

            GridView1.SelectedIndex = "0" ' works
            GridView1.EditIndex = "0" 'works

does not work
            GridView1.SelectedRow.Focus()
            GridView1.SelectedRow.Cells(2).Focus()

when a row is in edit mode I want the focus to be on the 2nd cell.
thanks
0
Comment
Question by:john
  • 5
  • 3
  • 2
10 Comments
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 38282949
Have you tried ActivateCell?

GridView1.ActivateCell(RECNO('table'),2)
0
 
LVL 20

Expert Comment

by:informaniac
ID: 38282952
Tried only

 GridView1.SelectedRow.Cells(2).Focus()

instead of

GridView1.SelectedRow.Focus()
GridView1.SelectedRow.Cells(2).Focus()

Not very sure if it will work though.
0
 

Author Comment

by:john
ID: 38283529
Neither solution works, actually they raise error.
I am using framework 3.5 ASP.net VB (C is ok too)

GridView1.SelectedIndex = "0" ' works
            GridView1.EditIndex = "0" 'works
this is in a subroutine so happens after page load.

IS there a "edit mode change event" that I should be using?
To focus the 2nd cell and top row(row 0) ?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 27

Expert Comment

by:CaptainCyril
ID: 38283561
I thought this was a FoxPro question !!!
0
 

Author Comment

by:john
ID: 38283687
I think the Row_Editing(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
event is where I should try to focus the 2nd cell.
in gridview I put    OnRowEditing="row_editing"

Need some syntax.
thanks
0
 

Accepted Solution

by:
john earned 0 total points
ID: 38284076
my solution, sorry guys  I found this to work.

  Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)


        If e.Row.RowType = DataControlRowType.DataRow Then
 

            Dim tb As TextBox = CType(e.Row.Cells(1).FindControl("tb_edit_fname"), TextBox)
            If Not IsNothing(tb) Then tb.Focus()

        End If
    End Sub
0
 
LVL 20

Expert Comment

by:informaniac
ID: 38286414
If e.Row.RowType = DataControlRowType.DataRow Then
  
if e.Row.RowIndex = GridView1.EditIndex Then
            Dim tb As TextBox = CType(e.Row.Cells(1).FindControl("tb_edit_fname"), TextBox)
            If Not IsNothing(tb) Then tb.Focus()
End If
        End If

Open in new window


Just a suggestion for better performance
0
 

Author Comment

by:john
ID: 38287436
I appreciate the additional information, by informaniac, not sure how I would grade the extra help. As we already implemented my earlier solution, but this new solution modification works also.
0
 
LVL 20

Expert Comment

by:informaniac
ID: 38289396
It's Ok. As long as it works. :)
0
 

Author Closing Comment

by:john
ID: 38304060
My solution works.
Experts took too long to provide an answer, no correct answer was provided by experts.
0

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…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
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

810 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