2013-03-23 52 views
1

我在表單上有一個GridView,即使Visible已在屬性窗口中設置爲True,但瀏覽器不可見。更重要的是,我有以下代碼來使數據在GridView的列中可見,但似乎沒有任何工作適合我。如果有人能幫助我,我會很高興。如何使GridView在VB.Net中可見

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

你能在設計師看到它嗎?它屬於哪個容器?任何相關的CSS? – OneFineDay 2013-03-23 16:38:13

+0

是的,我可以在設計器中看到GridView,但無法在瀏覽器中看到它。 – Akaglo 2013-03-23 16:42:47

+0

數據源必須爲空。 – 2013-03-23 17:30:55

回答

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 
2

好像你缺少爲GridViewDataBind()方法。

GridView1.DataSource = ds.Tables(0) 
GridView1.DataBind() // Add this