Object reference not set to an instance of an obje

Results 1 to 2 of 2

Thread: Object reference not set to an instance of an obje

  1. #1
    Join Date
    Dec 1969

    Default Object reference not set to an instance of an obje

    Receiving the above error when trying to run the Itembound event<BR>handler for datagrid1. The error message point to the following line as the problem:<BR><BR>quantity = Integer.Parse(drv.Row("Quantity").ToString())<BR>< BR>Below is my code for the event (Note: datagrid renders when this code is commented)<BR>--------------------------------------------------------------<BR>Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, _<BR>ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _<BR>Handles DataGrid1.ItemDataBound<BR> Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)<BR> Dim quantity As Integer<BR> quantity = Integer.Parse(drv.Row("Quantity").ToString())<BR> If (quantity &#060; 10) Then<BR> e.Item.BackColor = Color.Red<BR> End If<BR>End Sub<BR>--------------------------------------------------------------<BR><BR>Thanks,<BR><BR>bs<BR><BR> <BR>

  2. #2
    Join Date
    Dec 1969

    Default So debug...

    find out which object doesn&#039;t exist.<BR><BR>Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)<BR>If drv Is Nothing Then<BR> ... oops 1 ...<BR>End If<BR>Dim row As DataRow = drv.Row("Quantity") &#039; ?? is that right datatype?<BR>If row Is Nothing Then<BR> ... oops 2 ...<BR>End If<BR>Dim quantity As Integer<BR>quantity = Integer.Parse(row.ToString())<BR>...<BR><BR>****** **<BR><BR>By the way, good old CINT still works in VB:<BR> quantity = CInt(row.ToString())<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts