グリッドビューに SqlDataSource がバインドされている間に、グリッドビューに行を動的に追加しようとしています。データがまだバインドされている間にカスタム行を追加することは可能ですか? 私はvbでコーディングしています。
1 に答える
-1
行をグリッドビューに追加するのではなく、新しいデータをそのデータソースに追加してから、グリッドビューをバインドします。データはデータベースにある必要はありません。データを取得して、そのオブジェクトに追加できます。
Public Class MyWebForm
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim myList = generateNewList()
myList.Add(New FooBar(4, "Four"))
GridView1.DataSource = myList
GridView1.DataBind()
End Sub
Private Function generateNewList() As List(Of FooBar)
Dim mylist As New List(Of FooBar)
mylist.Add(New FooBar(1, "One"))
mylist.Add(New FooBar(2, "Two"))
mylist.Add(New FooBar(3, "Three"))
Return mylist
End Function
End Class
Public Class FooBar
Private Property myID As Integer
Private Property myName As String
Public Property id As Integer
Get
Return myID
End Get
Set(value As Integer)
myID = value
End Set
End Property
Public Property name As String
Get
Return myName
End Get
Set(value As String)
myName = value
End Set
End Property
Public Sub New(id As Integer, name As String)
myID = id
myName = name
End Sub
End Class
于 2013-05-17T13:48:13.587 に答える