Reputation: 127
I have a GridView
on a form and it's not visible the browser even though Visible
has been set to True
in the Property Window. More so, I have the following code to enable data to be visible in the columns of the GridView
, but nothing seems to work for me. I'd be glad if someone could help me out.
Sub showgrid()
Try
ds.Clear()
ada = New SqlDataAdapter("Select SubjectCode'Subject Code',SubjectName'Subject Name',SubjectType'Subject Type',UserId'User Id',Password from ProgramDetails.Subjects", cn)
ada.Fill(ds, "ProgramDetails.Subjects")
cmd = New SqlCommand("Select SubjectCode'Subject Code',SubjectName'Subject Name',SubjectType'Subject Type',UserId'User Id',Password from ProgramDetails.Subjects", cn)
ada.SelectCommand = cmd
ada.Fill(ds)
GridView1.DataSource = ds.Tables(0)
Catch ex As Exception
End Try
End Sub
Upvotes: 1
Views: 1377
Reputation: 4892
Seems like you are missing the DataBind()
method for GridView
.
GridView1.DataSource = ds.Tables(0)
GridView1.DataBind() // Add this
Upvotes: 2
Reputation: 127
Try
ds.Clear()
ada = New SqlDataAdapter("Select SubjectCode'Subject Code',SubjectName'Subject Name',SubjectType'Subject Type',UserId'User Id',Password from ProgramDetails.Subjects", cn)
ada.Fill(ds, "ProgramDetails.Subjects")
cmd = New SqlCommand("Select SubjectCode'Subject Code',SubjectName'Subject Name',SubjectType'Subject Type',UserId'User Id',Password from ProgramDetails.Subjects", cn)
ada.SelectCommand = cmd
ada.Fill(ds)
GridView1.DataSource = ds.Tables(0)
GridView1.DataBind()'binds the datasource to the GridView
Catch ex As Exception
End Try
Upvotes: 1