It looks like your three column are the keys for the grid - you could
utilize built in functionality - DataKeyNames property (comma separated) -
and do not have to create columns for them.
then on the postback you can use DataKeys[e.RowIndex] - it will return your
three values
Okay cool. So now I can retrieve the 3 invisible fields using
DataKeys but how do I retrieve the contents of a Template field text
box (txtLength)? I tried FindControl but it always returns nothing,
maybe I'm using it wrong? The GridView control is in a table which is
on the Content1 section.
I figured it out. THANKS to everyone for your help! I explained what
I did to solve the problem below in case anyone else is interested.
Instead of attempting to retrieve Invisible column data (which doesn't
work upon PostBack) I removed the columns from the DataView and I used
the DataKeys property instead:
gvParts.DataKeys(e.RowIndex).Item("StretchOut")
gvParts.DataKeys(e.RowIndex).Item("NumBends")
gvParts.DataKeys(e.RowIndex).Item("SN")
To retrieve a template field in my GridView control I used the
FindControl method:
Dim txtLengthBox As TextBox =
gvParts.Rows(e.RowIndex).Cells(7).FindControl("txtLength")
The Entire Code is here:
Protected Sub gvParts_RowUpdating(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles
gvParts.RowUpdating
Dim txtLengthBox As TextBox =
gvParts.Rows(e.RowIndex).Cells(7).FindControl("txtLength")
Dim CusVal As CustomValidator =
gvParts.Rows(e.RowIndex).Cells(7).FindControl("cvLength")
If Trim(txtLengthBox.Text) <> "120" And
gvParts.DataKeys(e.RowIndex).Item("StretchOut") = "48" And
gvParts.DataKeys(e.RowIndex).Item("NumBends") = "0" Then
'Do not allow the user to change the length of a sheet of
material. Sheets are always 120 inches in length.
CusVal.IsValid = False
txtLengthBox.Text = e.OldValues("Length")
e.NewValues("Length") = e.OldValues("Length")
Else
End If
End Sub