DotNet Tutorials

Server Intellect

 How to use IList Generic Interface to store data C#

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.
using 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 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();
}

If you're looking for a really good web host, try Server Intellect - we found the setup procedure and control panel, very easy to adapt to and their IT team is awesome!

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!
 
123 ASP

411 ASP

Dot Net Freaks

Server Intellect