

Navigator : Home > Tutorials > Advanced Technologies Tutorials > ...
Store Data with ArrayList using ASP.NET 2.0 and VB.NET
This tutorial will show you how to store data with ArrayList using ASP.NET 2.0 and VB.NET.
At first, you need to import the namespace from System.Collections. The System.Collections namespace contains classe ArrayList which Implements the IList interface using an array whose size is dynamically increased as required.
| Imports System.Collections |
If you're ever in the market for some great Windows web hosting, try Server Intellect. We have been very pleased with their services and most importantly, technical support.
In order to run the example, we will use the btn_get_Click to trigger the task. The code as following:
| Protected Sub btn_get_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_get.Click
Dim name As String = String.Empty Dim EmployeeList As ArrayList = New ArrayList() name = "Jake" EmployeeList.Add(name) name = "peter" EmployeeList.Add(name) name = "lily" EmployeeList.Add(name)
Me.GridView1.DataSource = EmployeeList Me.GridView1.DataBind() End Sub |
The front end StoreDataWithArraylistVB.aspx page looks something like this:
<div align="left" style="text-align: center"> <table>
<tr>
<td colspan="2" style="width: 402px"> <asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal"> <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" /> <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" /> <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" /> <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" /> <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" /> <AlternatingRowStyle BackColor="#F7F7F7" /> </asp:GridView> </td> </tr> <tr>
<td colspan="2" style="height: 26px; width: 402px;"> <asp:Button ID="btn_get" runat="server" Text="Get data from arraylist" OnClick="btn_get_Click" /></td> </tr> </table> </div> |
The flow for the code behind page is as follows
Need help with Windows Dedicated Hosting? Try Server Intellect. I'm a happy customer!
|
Imports System.Collections Partial Class _Default
Inherits System.Web.UI.Page Protected Sub btn_get_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_get.Click
Dim name As String = String.Empty
Dim EmployeeList As ArrayList = New ArrayList() name = "Jake" EmployeeList.Add(name) name = "peter" EmployeeList.Add(name) name = "lily" EmployeeList.Add(name)
Me.GridView1.DataSource = EmployeeList Me.GridView1.DataBind() End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' This tutorial is provided in part by Server Intellect Web Hosting Solutions http://www.serverintellect.com ' Visit http://www.DotNetTutorials.com for more ASP.NET Tutorials End Sub End Class |
Looking for the C#.NET 2005 Version? Click Here!
Looking for more ASP.NET Tutorials? Click Here!