DotNet Tutorials

Server Intellect

 How to use IList Generic Interface to store data VB.NET

IList Generic Interface represents a collection of objects that can be individually accessed by index. 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;

Try Server Intellect for Windows Server Hosting. Quality and Quantity!


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.

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 used over 10 web hosting companies before we found Server Intellect. Their dedicated servers and add-ons were setup swiftly, in less than 24 hours. We were able to confirm our order over the phone. They respond to our inquiries within an hour. Server Intellect's customer support and assistance are the best we've ever experienced.

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

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>

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
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!
Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!
 
123 ASP

411 ASP

Dot Net Freaks

Server Intellect