Click to See Complete Forum and Search --> : Datagrid / update command


zombie_man23
August 12th, 2005, 11:09 AM
I have a datagrid that pulls in the information. I have a Edit button that works fine. When I go to edit a row, and click the Update button, I get an error saying:
Object reference not set to an instance of an object.

The code breaks on the
dname = CType(e.Item.FindControl("txtDeceasedName"), TextBox).Text line.

VB Code:

'Retrieve the data from the DataGrid
Dim mID As Integer
Dim dname As String
Dim relatedto As String
Dim relationship As String
Dim dateofdeath As Date
Dim notes As String
Dim visitation As String
Dim funeral As String

mID = dgMemoriam.DataKeys(e.Item.ItemIndex)
dname = CType(e.Item.FindControl("txtDeceasedName"), TextBox).Text
relatedto = CType(e.Item.FindControl("txtRelatedTo"), TextBox).Text
relationship = CType(e.Item.FindControl("txtRelationship"), TextBox).Text
dateofdeath = CType(e.Item.FindControl("txtDateofDeath"), TextBox).Text
notes = CType(e.Item.FindControl("txtNotes"), TextBox).Text
visitation = CType(e.Item.FindControl("txtVisitation"), TextBox).Text
funeral = CType(e.Item.FindControl("txtFuneral"), TextBox).Text

Igor Soukhov
August 14th, 2005, 06:21 AM
I have a datagrid that pulls in the information. I have a Edit button that works fine. When I go to edit a row, and click the Update button, I get an error saying:
Object reference not set to an instance of an object.

The code breaks on the
dname = CType(e.Item.FindControl("txtDeceasedName"), TextBox).Text line.

VB Code:

'Retrieve the data from the DataGrid
Dim mID As Integer
Dim dname As String
Dim relatedto As String
Dim relationship As String
Dim dateofdeath As Date
Dim notes As String
Dim visitation As String
Dim funeral As String

mID = dgMemoriam.DataKeys(e.Item.ItemIndex)
dname = CType(e.Item.FindControl("txtDeceasedName"), TextBox).Text
relatedto = CType(e.Item.FindControl("txtRelatedTo"), TextBox).Text
relationship = CType(e.Item.FindControl("txtRelationship"), TextBox).Text
dateofdeath = CType(e.Item.FindControl("txtDateofDeath"), TextBox).Text
notes = CType(e.Item.FindControl("txtNotes"), TextBox).Text
visitation = CType(e.Item.FindControl("txtVisitation"), TextBox).Text
funeral = CType(e.Item.FindControl("txtFuneral"), TextBox).Text

You received this error because you're trying to
access uninitialized object (that may be the property of the other object) - in another words reference to the object initialized with null value.

Most probable cause of that problem is that object is not created yet.
Because your code breaks on this line:


dname = CType(e.Item.FindControl("txtDeceasedName"), TextBox).Text line.


please check - whether txtDeceasedName TextBox is created at this point or not. If not, - modify your code to ensure that the TextBox created before retrieving text from it.