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; |
Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!
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; } |
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.
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" /> </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" /> |
We are using Server Intellect and have found that by far, they are the most friendly, responsive, and knowledgeable support team we've ever dealt with!
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