R
RN1
A DataGrid has a TemplateColumn which, in turn, has a Label in the
ItemTemplate & a TextBox in the EditItemTemplate. The ID of the
TextBox is txtPhone. When the DataGrid is in the editable mode, I want
to retrieve the Text property of the TextBox in the OnPreRender event
handler of the DataGrid. This is how I tried it:
--------------------------------------------------------------------------------
Sub PreRenderGrid(ByVal obj As Object, ByVal ea As EventArgs)
If (dgUsers.EditItemIndex > -1) Then
Dim tb As TextBox
Dim dgi As DataGridItem
For Each dgi In dgUsers.Items
If (dgi.ItemType = ListItemType.Item Or dgi.ItemType =
ListItemType.AlternatingItem) Then
tb = CType(dgi.FindControl("txtPhone"), TextBox)
Response.Write(tb.Text)
End If
Next
End If
End Sub
--------------------------------------------------------------------------------
But when I click a link to change the DataGrid in the editable mode,
the following error gets generated:
Object reference not set to an instance of an object.
pointing to the Response.Write line in the above code.
What am I doing wrong?
ItemTemplate & a TextBox in the EditItemTemplate. The ID of the
TextBox is txtPhone. When the DataGrid is in the editable mode, I want
to retrieve the Text property of the TextBox in the OnPreRender event
handler of the DataGrid. This is how I tried it:
--------------------------------------------------------------------------------
Sub PreRenderGrid(ByVal obj As Object, ByVal ea As EventArgs)
If (dgUsers.EditItemIndex > -1) Then
Dim tb As TextBox
Dim dgi As DataGridItem
For Each dgi In dgUsers.Items
If (dgi.ItemType = ListItemType.Item Or dgi.ItemType =
ListItemType.AlternatingItem) Then
tb = CType(dgi.FindControl("txtPhone"), TextBox)
Response.Write(tb.Text)
End If
Next
End If
End Sub
--------------------------------------------------------------------------------
But when I click a link to change the DataGrid in the editable mode,
the following error gets generated:
Object reference not set to an instance of an object.
pointing to the Response.Write line in the above code.
What am I doing wrong?