K
K B
PLEASE be patient and read this. I believe I've actually reached the end
of the Web trying to find the answer!
I have an aspx using a MasterPage with a ContentPlaceholder.
I have a datatable that I use to dynamically populate a gridview - I
have to do this in order to specify which control type to put in one of
the columns. All this works fine. I've run Trace and can clearly see
that the control.id I assigned (lblQuestionID) is there
(UniqueID: ctl00$cphMain$gv1$ctl02$lblQuestionID for the first row).
Yet...on a button click event I try to get the control value...
Dim QuestionID as String= CType(gv1.FindControl("lblQuestionID"),
Label).Text
...returns "Object reference not set to an instance of an object" error.
***********************
This is how I load the gridview (abbreviated version):
Public Sub gv1_RowDataBound(ByVal sender As System.Object, ByVal e As
GridViewRowEventArgs) Handles gv1.RowDataBound
If e.Row.RowType = ListItemType.Item Or e.Row.RowType =
ListItemType.AlternatingItem Then
'put Question ID in first column
Dim lblID As New Label
lblID.ID = "lblQuestionID"
lblID.Text = dgTable(gv1).Rows(e.Row.DataItemIndex)(0)
e.Row.Cells(0).Controls.Add(lblID)
lblID.EnableViewState = True
I have other controls (dropdownlist, text, etc.) that I need to get the
new value of after being changed by the user. I can't get any control
values including the above example.
BTW, I tested the above FindControl syntax on a simple gridview with a
standard SqlDataSource datasource and it worked. My problem is that I
must use the dynamic controls. Also, I compared both gridview items in
Trace and they were identical right down to the UniqueIDs.
I'm begging anyone out there who could suggest a solution.
Kit
P.S. The following used to work on my old and truly missed datagrid:
QuestionID = CType(datagrid1.Rows(i).Cells(0).Controls(0), Label).Text
-- and I've tried variations such as Controls(2), etc.
of the Web trying to find the answer!
I have an aspx using a MasterPage with a ContentPlaceholder.
I have a datatable that I use to dynamically populate a gridview - I
have to do this in order to specify which control type to put in one of
the columns. All this works fine. I've run Trace and can clearly see
that the control.id I assigned (lblQuestionID) is there
(UniqueID: ctl00$cphMain$gv1$ctl02$lblQuestionID for the first row).
Yet...on a button click event I try to get the control value...
Dim QuestionID as String= CType(gv1.FindControl("lblQuestionID"),
Label).Text
...returns "Object reference not set to an instance of an object" error.
***********************
This is how I load the gridview (abbreviated version):
Public Sub gv1_RowDataBound(ByVal sender As System.Object, ByVal e As
GridViewRowEventArgs) Handles gv1.RowDataBound
If e.Row.RowType = ListItemType.Item Or e.Row.RowType =
ListItemType.AlternatingItem Then
'put Question ID in first column
Dim lblID As New Label
lblID.ID = "lblQuestionID"
lblID.Text = dgTable(gv1).Rows(e.Row.DataItemIndex)(0)
e.Row.Cells(0).Controls.Add(lblID)
lblID.EnableViewState = True
I have other controls (dropdownlist, text, etc.) that I need to get the
new value of after being changed by the user. I can't get any control
values including the above example.
BTW, I tested the above FindControl syntax on a simple gridview with a
standard SqlDataSource datasource and it worked. My problem is that I
must use the dynamic controls. Also, I compared both gridview items in
Trace and they were identical right down to the UniqueIDs.
I'm begging anyone out there who could suggest a solution.
Kit
P.S. The following used to work on my old and truly missed datagrid:
QuestionID = CType(datagrid1.Rows(i).Cells(0).Controls(0), Label).Text
-- and I've tried variations such as Controls(2), etc.