HI all.
I need to tranfer the records of one gridview to another gridview on checking the record.
I have used a button for this purpose. Check all the desired items and on button click the
records are transferred to the gridview. I have given the following code:

Protected Sub btnRight_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRight.Click
        Dim dtLeft As Data.DataTable = DirectCast(ViewState("dtleft"), Data.DataTable)
        Dim dtRight As Data.DataTable = DirectCast(ViewState("dtright"), Data.DataTable)
        For Each oItemLeft As GridViewRow In GridView1.Rows
            If DirectCast(GridView1.HeaderRow.Cells(0).FindControl("chk"), CheckBox).Checked Then
                dtRight.Rows.Add(GridView1.DataKeys(oItemLeft.DataItemIndex).Value, oItemLeft.Cells(1).Text, oItemLeft.Cells(2).Text)
                End If
        Next

        GridView1.DataSource = dtRight
        GridView1.DataBind()
        GridView2.DataSource = dtLeft
        GridView2.DataBind()

        ViewState("dtleft") = dtLeft
        ViewState("dtright") = dtRight

    End Sub

where dtright and dtleft are the datasets. An error is coming in the if statement saying
"Object reference not set to an instance of an object".I have tried with every tutorial that I came
across in the net. But could not solve the problem. Please someone help me. Thankyou.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.