DotNet Tutorials

V4 Dot Net Tutorials

Server Intellect Cloud Hosting

 IList Generic Interface using ASP.NET 2.0 and C#.NET

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.
using System.Collections.Generic;

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 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 void BindData()
{
IList<UserInfo> userinfos = new List<UserInfo>();
for (int i = 0; i < 5; i++)
{
UserInfo info = new UserInfo("username" + i.ToString(), "password" + i.ToString());
userinfos.Add(info);
}
this.GridView1.DataSource = userinfos;
this.GridView1.DataBind();
}

I just signed up at Server Intellect and couldn't be more pleased with my Windows Server! Check it out and see for yourself.

I add one userinfo custom class which is used to store data.The code as follow:

using System;

/// <summary>
/// UserInfo
/// </summary>
public class UserInfo
{
private string _userName = string.Empty;
private string _password = string.Empty;

public UserInfo()
{

}

public UserInfo(string userName, string password)
{
this._userName = userName;
this._password = password;
}

public string UserName
{
get
{
return _userName;
}
}

public string Password
{
get
{
return _password;
}
}
}

The front end TemplateCsharp.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.

We migrated our web sites to Server Intellect over one weekend and the setup was so smooth that we were up and running right away. They assisted us with everything we needed to do for all of our applications. With Server Intellect's help, we were able to avoid any headaches!


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
BindData();
}

private void BindData()
{
IList<UserInfo> userinfos = new List<UserInfo>();
for (int i = 0; i < 5; i++)
{
UserInfo info = new UserInfo("username" + i.ToString(), "password" + i.ToString());
userinfos.Add(info);
}
this.GridView1.DataSource = userinfos;
this.GridView1.DataBind();
}
}




Looking for the VB.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!