Tuesday, July 15, 2008

Bind Repeater to an ArrayList

from http://stanleycn.blogspot.com/2006/10/how-to-bind-arraylist-to-repeater.html

aspx


< id="rptDestinations" runat="server" onitemdatabound="rptDestinations_ItemDataBound">
<>
< id="lblDestinationName" runat="server" text=""> " > < / a s p : Label >
< / ItemTemplate >
< / a s p : Repeater>


aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
rptDestinations.DataSource = GetDestinations();
rptDestinations.DataBind();
}

private ArrayList GetDestinations()
{
ArrayList arrayList = new ArrayList();

foreach (DataRow dr in _ds.Tables[0].Rows)
{
if (!arrayList.Contains(dr["DestinationName"]))
{
arrayList.Add(dr["DestinationName"]);
}
}

return arrayList;
}

No comments: