Solved

Gridview RowEditing Can't FindControl

Posted on 2013-02-01
5
1,267 Views
Last Modified: 2013-02-07
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

0
Comment
Question by:rcl58
[X]
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
  • 2
  • 2
5 Comments
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 500 total points
ID: 38845308
Check:
http://www.experts-exchange.com/Microsoft/Server_Applications/Q_24474303.html

The e.NewEditIndex value is relative to gv page you are displaying, thus you need to calculate the correct Index. (Insert at line 2)
Dim correctIndex As Integer = e.NewEditIndex
If (GridView1.PageIndex > 0) Then
  correctIndex = e.NewEditIndex + (GridView1.PageSize * GridView1.PageIndex
EndIf

Open in new window

Then use correctIndex in all your code lines 3 to11. (instead of e.NewEditIndex)
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 38845486
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()
0
 

Author Comment

by:rcl58
ID: 38859213
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.
0
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 38861833
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.
0
 

Author Comment

by:rcl58
ID: 38865596
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

622 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