Web Services PHP - Grid .NET Step By Step Tutorial - Part 6: Last, we will add code for button. When use click button, it retrieve data from server then display to datagrid.
First, create a class named "test_book". You can add item from menu bar: Project > Add Class. Enter name "test_book.vb". Then enter this code:
Public Class test_book
Private _id As Integer
Private _title As String
Private _author As String
Public Sub New(ByVal id As Integer, ByVal title As String, ByVal author As String)
_id = id
_title = title
_author = author
End Sub
Public ReadOnly Property id() As Integer
Get
Return _id
End Get
End Property
Public ReadOnly Property title() As String
Get
Return _title
End Get
End Property
Public ReadOnly Property author() As String
Get
Return _author
End Get
End Property
Public Overloads Overrides Function ToString() As String
Return String.Format("{0}#{1}#{2}", _id, _title, _author)
End Function
End Class
Next, Double click on button. Then enter following code:
Dim arl As New ArrayList
Dim ws As New library.LibraryService
Dim str As String = ws.doLibrary("")
'split each row into array
Dim arr As Array = str.Split("#")
Dim book(3) As String
For Each item As Object In arr
If item <> Nothing Then
'split each item
book = Convert.ToString(item).Split("|")
arl.Add(New test_book(book(0), book(1), book(2)))
End If
Next
DataGrid1.DataSource = arl
DataGrid1.Refresh()
Now, try to test it.
