Infolink

 

Search This Blog

Nov 8, 2012

IList Generic Interface

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;

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 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.
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 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;
}
}

 
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!

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> 


Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!
The flow for the code behind page is as follows.


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

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...