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 ContentPlacehol der.
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$g v1$ctl02$lblQue stionID for the first row).
Yet...on a button click event I try to get the control value...
Dim QuestionID as String= CType(gv1.FindC ontrol("lblQues tionID"),
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_RowDataBoun d(ByVal sender As System.Object, ByVal e As
GridViewRowEven tArgs) Handles gv1.RowDataBoun d
If e.Row.RowType = ListItemType.It em Or e.Row.RowType =
ListItemType.Al ternatingItem Then
'put Question ID in first column
Dim lblID As New Label
lblID.ID = "lblQuestio nID"
lblID.Text = dgTable(gv1).Ro ws(e.Row.DataIt emIndex)(0)
e.Row.Cells(0). Controls.Add(lb lID)
lblID.EnableVie wState = 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.
*** Sent via Developersdex http://www.developersdex.com ***