I am trying to pass the datatable of a search query to another page and bind it to a listbox. The problem is the the listbox just displays system.data.datarowview and no results.

I have listed the code below.


First page SQL and session store:

Protected Sub btnSearch_Click(sender As Object, e As System.EventArgs) Handles btnSearch.Click
        Dim ConnString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString()

        Dim connection As New SqlConnection(ConnString)

        Dim adapter As New SqlDataAdapter("SELECT VideoName, VideoNo FROM Video where VideoName='" & txtSearch.Text & "'", connection)

        Dim dt As New DataTable

        Session("Results") = dt

    End Sub

Second page loading the session

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        If Session("Results") IsNot Nothing Then

            Dim dtnew As DataTable = DirectCast(Session("Results"), DataTable)

            lstResults.DataSource = dtnew

            'listbox data
            lstResults.DataMember = "VideoName"
            'bind the listbox

            lblerror.Text = "No Results"
        End If
Be a part of the DaniWeb community

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