我在表单上有一个GridView
,即使Visible
已在属性窗口中设置为True
,也无法在浏览器中看到它。更重要的是,我有以下代码来使数据在GridView
的列中可见,但似乎没有什么对我有用。如果有人可以帮助我,我会很高兴。
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
答案 0 :(得分:2)
好像你错过了DataBind()
的{{1}}方法。
GridView
答案 1 :(得分:1)
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