Thursday, September 16, 2010

Example how to create arraylist and bind it to datalist

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
namespace examples_Post
{
public partial class exp9 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Creating the arraylist values to bind them to datalist
ArrayList myarraylist = new ArrayList(3);
myarraylist.Add("Damien");
myarraylist.Add("David");
myarraylist.Add("Campbell");
myarraylist.Add("Cairns");
myarraylist.Add("Anthony");
myarraylist.Add("Cieran");
// Setting the datasource property of datalist to the array 'myarraylist'
dlTest.DataSource = myarraylist;


//Binding the myarraylist values to datalsit
dlTest.DataBind();
}
}
}






==


<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="dlTest" runat="server" ForeColor="#000000" BackColor="Beige"
CellPadding="3" GridLines="none" Width="50%">
<ItemStyle Font-Size="Large" BackColor="Beige"/>
<AlternatingItemStyle Font-Size="Medium" BackColor="Orchid" />
<ItemTemplate>
<%# Container.DataItem %>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>

No comments:

Post a Comment