troubleshooting Question

Gridview does not load (asp.net site)

Avatar of adamtrask
adamtrask asked on
ASP.NETVisual Basic.NET
3 Comments1 Solution343 ViewsLast Modified:
I have a gridview to display some content. It works fine when the page first loads. But once we move to the next page and the user wants to go back to the gridview page because he decided to change his selection, the gridview does not load and the data is not displayed.
What is wrong......?

I have put the code that loads the gridview in the page's Load event but the same is happening:

Here is the code that loads the page and the gridView
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       
        Dim sInstructorName As String = Session("InstructorUS") ' instructorUS contains the userName
        Dim takenSurvey As String = "n"
        Dim con As SqlConnection
        Dim comm As SqlCommand
        Dim reader As SqlDataReader
        Dim connectionString As String = ConfigurationManager.ConnectionStrings("Survey").ConnectionString
        con = New SqlConnection(connectionString)
        comm = New SqlCommand("Select ID, courseID, course from InstructorsSurvey where UserName=@UserName And taken=@taken", con)
        comm.Parameters.AddWithValue("@UserName", System.Data.SqlDbType.NVarChar)
        comm.Parameters("@UserName").Value = sInstructorName ' instructor's userName
        comm.Parameters.AddWithValue("@taken", System.Data.SqlDbType.NVarChar)
        comm.Parameters("@taken").Value = takenSurvey
        con.Open()
        reader = comm.ExecuteReader
        myGrid.DataSource = reader
        myGrid.DataBind()
        reader.Close()
        con.Close()
    End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       
        Dim sInstructorName As String = Session("InstructorUS") ' instructorUS contains the userName
        Dim takenSurvey As String = "n"
        Dim con As SqlConnection
        Dim comm As SqlCommand
        Dim reader As SqlDataReader
        Dim connectionString As String = ConfigurationManager.ConnectionStrings("Survey").ConnectionString
        con = New SqlConnection(connectionString)
        comm = New SqlCommand("Select ID, courseID, course from InstructorsSurvey where UserName=@UserName And taken=@taken", con)
        comm.Parameters.AddWithValue("@UserName", System.Data.SqlDbType.NVarChar)
        comm.Parameters("@UserName").Value = sInstructorName ' instructor's userName
        comm.Parameters.AddWithValue("@taken", System.Data.SqlDbType.NVarChar)
        comm.Parameters("@taken").Value = takenSurvey
        con.Open()
        reader = comm.ExecuteReader
        myGrid.DataSource = reader
        myGrid.DataBind()
        reader.Close()
        con.Close()
    End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros