Link to home
Start Free TrialLog in
Avatar of rcl58
rcl58

asked on

Gridview RowEditing Can't FindControl

When entering Edit mode on my GridView I place the focus on a field with the FindControl method. All is well, but if I move to page #2 my code crashes, (ArgumentOutOfRangeException).

What am I doing wrong??

 Private Sub gv_Gifts_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gv_Gifts.RowEditing
       
        If gv_Gifts.EditIndex = e.NewEditIndex Then
            e.Cancel = True
            Exit Sub
        End If

        gv_Gifts.EditIndex = e.NewEditIndex
        LoadOffers()

        gv_Gifts.Rows(e.NewEditIndex).FindControl("giftTitle").Focus()

    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You need to rebind your GV before getting the control. So is your LoadOffers() rebinding the GV?

gv_Gifts.EditIndex = e.NewEditIndex
gv_Gifts.DataBind()
Avatar of rcl58
rcl58

ASKER

Oops, the accepted solution is not working , same problem.

After going to page 2 and entering edit on the first row
e.NewEditIndex = 10
.PageSize = 10
.PageIndex = 1

Suggestion "correctIndex = e.NewEditIndex + (GridView1.PageSize * GridView1.PageIndex)" result in a value of 20.

Also the binding code change suggestion didn't help:

gv_Gifts.EditIndex = e.NewEditIndex
gv_Gifts.DatBind()

I'm still lost and may have to repost because I already accepted the solution.
is the gridview binding in markup? I f no, please post which event(s) are binding the gridview dynamically.
Can you post the exception details?
Also if you can post the contents of gv_Gifts.Rows before the exception is thrown. I am interested in the count property whether Rows(0) is the actual first row or is the 11 row.
NOte: 1) IF you can include before/after values of my suggested code changes will be great.
2) No need to ask a new question, just request the moderator to reopen the question.