Loading ...

Bind Repeater With ArrayList | CodeAsp.Net

Bind Repeater With ArrayList

 /5
0 (0votes)

Many times we want to bind the Repeater with ArrayList.We can use Data Source property of Repeater for binding with Array List.
Following is HTML page code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"
Title="Bind Repeater With ArrayList" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<b>Name</b>
</td>
</tr>
<asp:Repeater ID="rptBindWithArrayList" runat="server">
<ItemTemplate>
<tr>
<td>
<%#Container.DataItem %>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</div>
</form>
</body>
</html>


follwoing is C# Code:

protected void Page_Load(object sender, EventArgs e)
{
     if(!IsPostBack)
    {
      BindRepeater();
   }
}
private void BindRepeater()
{
     ArrayList arrayList = new ArrayList();
    arrayList.Add("Vijendra Singh");
    arrayList.Add("Mohd Asif");
    arrayList.Add("Vinay Gupta");
    arrayList.Add("Sumit Arora");
    arrayList.Add("Shaitender Singh");
    rptBindWithArrayList.DataSource = arrayList;
    rptBindWithArrayList.DataBind();   
}


Hope it will help..Frown

 

Comments (no comments yet)

  • :*
  • :*
  • :
 *

Top Posts