OnPreRender

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top