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; |
We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.
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) End Sub 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() |
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.
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 End Class 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 End SubMe._password = password Public ReadOnly Property UserName() As String Get End PropertyReturn _userName End GetPublic ReadOnly Property Password() As String Get End PropertyReturn _password End Get |
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" /> </asp:GridView> <Columns> <asp:BoundField DataField="UserName" HeaderText="UserName" /> </Columns><asp:BoundField DataField="Password" HeaderText="Password" /> <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" /> |
Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.
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 End Class Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then End SubBindData() End IfPrivate Sub BindData() Dim userinfos As IList(Of UserInfo) = New List(Of UserInfo) End SubDim i As Integer For i = 0 To 4 Dim info As New UserInfo("username" + i.ToString(), "password" + i.ToString()) Next iuserinfos.Add(info) Me.GridView1.DataSource = userinfos Me.GridView1.DataBind() |
No comments:
Post a Comment