Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nested Datagrid Question

Status
Not open for further replies.

NatGreen

Programmer
Apr 19, 2002
90
US

I am having a problem finding the child datagrid from the Parent update command. I would like to loop through the values to do some validation.

Code:
 Public Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
        Try
            Dim dgTemp As DataGrid = (CType(source, DataGrid))
            DataGrid1.EditItemIndex = -1

            Dim dgtempSub As DataGrid = (CType(e.Item.FindControl("DataGrid2"), DataGrid))

            Dim blType As New Bl.Type(constr)

            Dim TempList As New DropDownList
            Dim TempValue As Integer
            TempList = e.Item.FindControl("ddlID")
            TempValue = CInt(TempList.SelectedValue)

            Dim dgItem As DataGridItem

            For Each dgItem In dgtempSub.Items
                If CInt(e.Item.Cells(3).Text) <> TempValue Then
                    blType.Insert(TempValue, ddlType.SelectedValue)
                End If
            Next

            BindData()

        Catch exc As Exception

        End Try
    End Sub

I get an error on:

Line: For Each dgItem In dgtempSub.Items
Error: "Object reference not set to an instance of an object"


Any help would be appreciated.

Thanks!
NatGreen
 
It may be because you've just declared a datagrid object, you've not actually instantiated it. e.g. you have wrote

Code:
Dim dgtempSub As DataGrid = (CType(e.Item.FindControl("DataGrid2"), DataGrid))

Try the following and see if that makes a difference:
Code:
Dim dgtempSub As New DataGrid = (CType(e.Item.FindControl("DataGrid2"), DataGrid))

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Unfortunately that didn't work. Sees as if it can't find DataGrid2 reason.

Thanks.
NatGreen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top