【发布时间】:2017-05-19 07:36:55
【问题描述】:
我尝试从一个 gridview 复制到另一个 gridview 我试试这个
Dim dt As New DataTable()
For Each cell As TableCell In GridView1.HeaderRow.Cells
dt.Columns.Add(cell.Text)
Next
For Each row As GridViewRow In GridView1.Rows
dt.Rows.Add()
For i As Integer = 0 To row.Cells.Count - 1
dt.Rows(row.RowIndex)(i) = row.Cells(i).Text
Next
Next
GridView2.DataSource = dt
GridView2.DataBind()
但这显示错误
A column named 'Amount' already belongs to this DataTable.
作为我的 SP,我没有重复的列
【问题讨论】:
-
您是否使用调试器查看了所有 cell.Text 值?
-
是的,一切都正确,但数量上显示错误
-
您是否检查过第一个循环中是否有两个标题单元格具有相同的文本“金额”?当您添加与另一列同名的第二列时,将在第一个循环中引发异常。你如何构建 GridView-header,它是静态的吗?
-
没有 2 个带有文本“金额”的标题文本..我将数据从一个网格视图传输到另一个网格视图
-
@TimSchmelter ???????