Repeater controls bind arrays and ArrayList implementations respectively

  • 2020-05-24 05:19:13
  • OfStack

Foreground code:
 
<asp:Repeater ID="rptarry" runat="server" > 
<HeaderTemplate><table></HeaderTemplate> 
<ItemTemplate> 
<tr><td> <%# GetDataItem()%> </td></tr> 
</ItemTemplate> 
<FooterTemplate></table></FooterTemplate> 
</asp:Repeater> 
<asp:Repeater ID="rptarryList" runat="server"> 
<HeaderTemplate><table></HeaderTemplate> 
<ItemTemplate> 
<tr><td> <%# GetDataItem()%> </td></tr> 
</ItemTemplate> 
<FooterTemplate></table></FooterTemplate> 
</asp:Repeater> 

Background code:
 
public void bindrptarry() 
{ 
string strs = "li|wen|yuan"; 
string[] str = strs.Split('|'); 
rptarry.DataSource =str; 
rptarry.DataBind(); 
} 
public void bindrptarryList() 
{ 
string strs = "li|wen|yuan"; 
string[] str = strs.Split('|'); 
rptarry.DataSource = arrayList(); 
rptarry.DataBind(); 
} 
public ArrayList arrayList() 
{ 
ArrayList aL = new ArrayList(); 
aL.Add("liceshi"); 
aL.Add("wenceshi"); 
aL.Add("yuanceshi"); 
return aL; 
} 

Bind the data source (array or ArrayList) with DataSource in the background and call the DataBind() method,
Call in the foreground < %# GetDataItem()% > .

If there is anything wrong, you are welcome to correct it and make progress together.

Related articles: