Solved

Gridview RowEditing Can't FindControl

Posted on 2013-02-01
5
1,246 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
  • 2
  • 2
5 Comments
 
LVL 35

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 35

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now