在aspx页面的代码后面,我有一个数据表:
Dim people As DataTable = New DataTable()
people.Columns.Add("ID", System.Type.GetType("System.Int32"))
people.Columns.Add("FirstName", System.Type.GetType("System.String"))
people.Columns.Add("LastName", System.Type.GetType("System.String"))
people.Rows.Add(10, "Merci", "Beaucoup")
这是GridViewData:(不是asp:GridView)
Dim gvPeople As System.Windows.Forms.DataGridView = New DataGridView()
gvPeople.AutoGenerateColumns = False
'Set Columns Count
gvPeople.ColumnCount = 3
'Add Columns
gvPeople.Columns(0).Name = "ID"
gvPeople.Columns(0).HeaderText = "ID"
gvPeople.Columns(0).DataPropertyName = "ID"
gvPeople.Columns(1).Name = "FirstName"
gvPeople.Columns(1).HeaderText = "FirstName"
gvPeople.Columns(1).DataPropertyName = "FirstName"
gvPeople.Columns(2).Name = "LastName"
gvPeople.Columns(2).HeaderText = "LastName"
gvPeople.Columns(2).DataPropertyName = "LastName"
这里我将DataGridView的数据源设置为DataTable:
gvPeople.DataSource = people
当我使用 DataGridView 将 DataGridView 导入 Excel 工作表Gembox.Spreadsheet
时,它只显示 DataGridView 的 headerText 而没有数据。这是导入代码:
DataGridViewConverter.ImportFromDataGridView(ws, gvPeople, New ImportFromDataGridViewOptions() With _
{
.ColumnHeaders = True,
.StartRow = 8,
.StartColumn = 0
})
我尝试了多种方法,例如:
设置
.DataMember
DataTable 名称:gvPeople.DataMember=people.TableName
Refresh()
或Update()
分配.Datasource
.
注意:这不是 a asp:GridView
,它是 aDataGridView
并且没有DataBind()
方法。