This example demonstrates how to use IList Generic Interface to store data.
This example demonstrates how to use IList Generic Interface to store data.
IList Generic Interface represents a collection of objects that can be individually accessed by index.
First, you will need to import the System.Collections.Generic namespace.
| Imports System.Collections.Generic; |
The System.Collections.Generic namespace contains interfaces and classes that define generic collections, which allow users to create strongly typed collections that provide better type safety and performance than non-generic strongly typed collections.
Yes, it is possible to find a good web host. Sometimes it takes a while. After trying several, we went with Server Intellect and have been very happy. They are the most professional, customer service friendly and technically knowledgeable host we've found so far.
We use the BindData function to do the work.
We use GridView control to display data. The code as follow:
Private Sub BindData()
Dim userinfos As IList(Of UserInfo) = New List(Of UserInfo) Dim i As Integer For i = 0 To 4
Dim info As New UserInfo("username" + i.ToString(), "password" + i.ToString()) userinfos.Add(info) Next i Me.GridView1.DataSource = userinfos Me.GridView1.DataBind() End Sub |
We moved our web sites to Server Intellect and have found them to be incredibly professional. Their setup is very easy and we were up and running in no time.
I add one userinfo custom class which is used to store data.The code as follow:
Imports System
'/ <summary> '/ UserInfo '/ </summary>
Public Class UserInfo
Private _userName As String = String.Empty Private _password As String = String.Empty Public Sub New() End Sub Public Sub New(ByVal userName As String, ByVal password As String)
Me._userName = userName Me._password = password End Sub Public ReadOnly Property UserName() As String
Get
Return _userName End Get End Property Public ReadOnly Property Password() As String
Get
Return _password End Get End Property End Class |
I just signed up at Server Intellect and couldn't be more pleased with my Windows Server! Check it out and see for yourself.
The front end TemplateVB.aspx page looks something like this:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal">
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" /> <Columns>
<asp:BoundField DataField="UserName" HeaderText="UserName" /> <asp:BoundField DataField="Password" HeaderText="Password" /> </Columns> <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> |
Need help with Windows Dedicated Hosting? Try Server Intellect. I'm a happy customer!
The flow for the code behind page is as follows.
Imports System Imports System.Data Imports System.Configuration Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls Imports System.Collections.Generic
Partial Class _Default
Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
BindData() End If End Sub Private Sub BindData()
Dim userinfos As IList(Of UserInfo) = New List(Of UserInfo) Dim i As Integer For i = 0 To 4
Dim info As New UserInfo("username" + i.ToString(), "password" + i.ToString()) userinfos.Add(info) Next i Me.GridView1.DataSource = userinfos Me.GridView1.DataBind() End Sub End Class |
Looking for the C#.NET 2005 Version? Click Here!
Looking for more ASP.NET Tutorials? Click Here!