Solved

How to reference a bound column from RowUpdating of GridView control

Posted on 2008-09-29
3
591 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 500 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

789 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