

Navigator : Home > Tutorials > Advanced Technologies Tutorials > ...
Store Data with ArrayList using ASP.NET 2.0 and C#
This tutorial will show you how to store data with ArrayList using ASP.NET 2.0 and C#.
At first, you need to import the namespace from System.Collections. The System.Collections namespace contains classe ArrayList which Implements the IList interface using an array whose size is dynamically increased as required.
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!
In order to run the example, we will use the btn_get_Click to trigger the task. The code as following:
protected void btn_get_Click(object sender, EventArgs e) {
string name = string.Empty;
ArrayList EmployeeList = new ArrayList(); name = "Jake"; EmployeeList.Add(name); name = "peter"; EmployeeList.Add(name); name = "lily"; EmployeeList.Add(name);
this.GridView1.DataSource = EmployeeList; this.GridView1.DataBind(); } |
The front end StoreDataWithArraylistCsharp.aspx page looks something like this:
<div align="left" style="text-align: center"> <table>
<tr>
<td colspan="2" style="width: 402px"> <asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal"> <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" /> <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> </td> </tr> <tr>
<td colspan="2" style="height: 26px; width: 402px;"> <asp:Button ID="btn_get" runat="server" Text="Get data from arraylist" OnClick="btn_get_Click" /></td> </tr> </table> </div> |
The flow for the code behind page is as follows
Yes, it is possible to find a good web host. Sometimes it takes a while. After trying several, we went with Server Intellect and have been very happy. They are the most professional, customer service friendly and technically knowledgeable host we've found so far.
|
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;
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
// This tutorial is provided in part by Server Intellect Web Hosting Solutions http://www.serverintellect.com // Visit http://www.DotNetTutorials.com for more ASP.NET Tutorials } protected void btn_get_Click(object sender, EventArgs e) {
string name = string.Empty;
ArrayList EmployeeList = new ArrayList(); name = "Jake"; EmployeeList.Add(name); name = "peter"; EmployeeList.Add(name); name = "lily"; EmployeeList.Add(name);
this.GridView1.DataSource = EmployeeList; this.GridView1.DataBind(); } } |
Looking for the VB.NET 2005 Version? Click Here!
Looking for more ASP.NET Tutorials? Click Here!