troubleshooting Question

Got error when retrieving the current text value out of a gridview control during gridview Updating event.

Avatar of lapucca
lapucca asked on
C#ASP.NET.NET Programming
11 Comments1 Solution272 ViewsLast Modified:
Hi, I'm using vs2012.
I used the code form msdn,

However, I'm getting out range error in run time.    Attached is my code snipet.  The error happens at
 "var sam = ((TextBox)(editRow.Cells[1].Controls[0])).Text;"

I think that the code is taking the row that is being edited (editRow is correct when I examine the property).  Cell 0 I think is the Edit button on my grid, it shows as the first column.  So cells[1] is the column that I want.  Examine the property of Cells show it has count of 6 and that is correct, 1st one is the Edit button generated by gridview control  however, the error is with Controls[0] being out of range.  

In the aspx file, the 1st cell is a boundfield, code as below
<asp:BoundField DataField ="sAMAccountName" HeaderText="User ID" ReadOnly="True" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle"></asp:BoundField>

Appreciate help here to fix the problem.  Thank you.

I add editRow.Cells to the Watch and there is a cells[1] object.  But I don't know how to expand to see where is the Controls[0] because that's where I get the error.  I'm attaching the screen shot for this too.

further examination by adding to the Watch panel, I found the error is caused because Cells[1].Controlls.count is 0.  I'm also attaching a screen shot for this.  Why is that so?  It does display the data that it's bound to.  How can I fix this?
Thank you.
Miguel Oz
Senior Software Engineer
Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros