這很簡單。你所要做的就是把你的網格綁定到任何一個Colleciton上,比如List,Array,DataTable。創建記錄類
Public Class MyRecord
Private _name As String = ""
Private _grade As Integer = ""
Public Property Name() As String
Get
Return Me._name
End Get
Set(ByVal value As String)
Me._name = Value
End Set
End Property
Public Property Grade() As Integer
Get
Return Me._grade
End Get
Set(ByVal value As Integer)
Me._grade = Value
End Set
End Property
End Class
在你的Page_Load綁定網格列出
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPotback Then
Dim list As New List(Of MyRecord)()
list.Add(New MyRecord() With { _
Key .Name = "dsfsdf", _
Key .Grade = 45 _
})
list.Add(New MyRecord() With { _
Key .Name = "dsfsd234f", _
Key .Grade = 50 _
})
Session("MyList") = list
GridView1.DataSource = list
GridView1.DataBind()
End If
End Sub
然後用文本框和按鈕添加某種形式和處理按鈕on_click事件
Protected Sub btn_Click(sender As Object, e As EventArgs) Handles btn.Click
Dim list As New List(Of MyRecord)
If Session("MyList") Is Not Nothing Then
list = DirectCast(Session("MyList"), List(Of MyRecord))
End If
list.Add(New MyRecord() With { _
Key .Name = txt1.Text, _
Key .Grade = Convert.ToInt32(txt2.Text) _
})
GridView1.DataSource = list
GridView1.DataBind()
End Sub
很抱歉,如果有任何錯誤,我是一個C#開發人員
可以請你提供你的aspx標記和代碼 – fenix2222