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

        GridView1.DataSource = dtRight
        GridView2.DataSource = dtLeft

        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.

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

7 Years
Discussion Span
Last Post by __avd
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.