Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to reference a bound column from RowUpdating of GridView control

Posted on 2008-09-29
3
Medium Priority
?
598 Views
Last Modified: 2013-11-07
Dear Experts,
I have a GridView I use for tracking shift times in a time clock application. If a user edits a row, I want to track the changes. In the RowUpdating event of the GV, I am simply trying to reference a bound column ("STShiftTimeID") to pass to my update table. I have tried:
DirectCast(gvShiftTimes.FindControl("STShiftTimeID"),Label) - using STShiftTime as a bound column;
DirectCast(gvShiftTimes.FindControl("txtSTShiftTimeID"),TextBox) - using txtSTShiftTimeID as a text box in a template and keep getting the NullReferenceException error. I have checked spelling and no typos.
I also check the e.Keys, e.NewValues, and e.OldValues of the Time-In and Time-Out controls, which work fine. If I try to find the STShiftTimeID value using either of those e values, it just comes back as zero, though I can see the STShiftTimeID in the grid.
So Experts, please, how do I reference the STShiftTimeID in my gridview control?
Thank you.
Dim tbxSTShiftTimeID As TextBox = CType(gvShiftTimes.FindControl("txtSTShiftTimeID"), TextBox)
        Dim iShiftTimeID As Integer = 0
        If tbxSTShiftTimeID.Text IsNot Nothing Then
            iShiftTimeID = tbxSTShiftTimeID.text
        End If

Open in new window

0
Comment
Question by:MCallas
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
prairiedog earned 2000 total points
ID: 22600655
Change this line to the attached snippet:
Dim tbxSTShiftTimeID As TextBox = CType(gvShiftTimes.FindControl("txtSTShiftTimeID"), TextBox)
 

Dim row As GridViewRow = Me.gvMemberLogs.Rows(e.RowIndex)
Dim tbxSTShiftTimeID As TextBox = CType(row.FindControl("txtSTShiftTimeID"), TextBox)

Open in new window

0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22600664
Sorry, change "gvMemberLogs" to "gvShiftTimes"
0
 

Author Closing Comment

by:MCallas
ID: 31501365
Thanks, prairiedog, for your quick and accurate reply (and for restoring what was left of my sanity).
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

916 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