主题:请教一个DataGrid的问题,谢谢
yusiyuan
[专家分:10] 发布于 2005-12-02 17:35:00
在不更改DataGrid中原有的数据下,怎样增加一条新的数据呢?
就是我每按一次我的查询按钮,就会有一组类似的数据增加到DataGrid1中去如:
某一次的查询需要显示的数据如: 001 20 30 10 50 90
下一个数据又可能是: 006 10
再下一个又可能是: 003 19 36 28
(第1个数据是题号,后面的都是相关类型的值)
就是要显示的数据个数不确定,我想在DataGrid中显示也会有长有短的.
不知道这样的数据怎样才能在DataGrid中显示,或者有别的好方法.谢谢~~~
回复列表 (共2个回复)
沙发
chenjin145 [专家分:200] 发布于 2005-12-02 19:49:00
Private Shared myTable As DataTable = New DataTable("eg")
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Not Page.IsPostBack Then
Dim i As Integer
For i = 0 To 5
Dim myColumn As DataColumn = New DataColumn
myColumn.DataType = System.Type.GetType("System.String")
myColumn.AllowDBNull = True
myColumn.Caption = "string" & i
myColumn.ColumnName = "string" & i
myTable.Columns.Add(myColumn)
Next
Dim myRow As DataRow
myRow = myTable.NewRow
myRow.ItemArray = New String() {"001", "20", "30", "10", "50", "90"}
myTable.Rows.Add(myRow)
DataGrid1.DataSource = myTable
DataGrid1.DataBind()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myRow As DataRow
myRow = Me.myTable.NewRow
myRow.ItemArray = New String() {"1", "2"}
Me.myTable.Rows.Add(myRow)
DataGrid1.DataSource = myTable
DataGrid1.DataBind()
End Sub
这样可以嘛?
板凳
yusiyuan [专家分:10] 发布于 2005-12-03 09:41:00
谢谢~~~~~~~~
我来回复