ASP.NET - రిపీటర్ కంట్రోల్

రిపీటర్ కంట్రోల్ పునరావృత ప్రతిస్థాపక జాబితాలను ప్రదర్శించడానికి ఉపయోగిస్తారు, ఈ ప్రతిస్థాపకలు కంట్రోల్లో పరిమితం.

DataSet ను రిపీటర్ కంట్రోల్కు అనుబంధం చేయడం

రిపీటర్ కంట్రోల్ పునరావృత ప్రతిస్థాపక జాబితాలను ప్రదర్శించడానికి ఉపయోగిస్తారు, ఈ ప్రతిస్థాపకలు కంట్రోల్లో పరిమితం. రిపీటర్ కంట్రోల్ డేటాబేస్ పట్టిక, XML ఫైలు లేదా ఇతర ప్రతిస్థాపక జాబితాలకు అనుబంధం కావచ్చు. ఇక్కడ, మేము XML ఫైలును రిపీటర్ కంట్రోల్కు అనుబంధం చేయడాన్ని ప్రదర్శిస్తాము.

ఈ ఉదాహరణలో క్రింది XML ఫైలును ("cdcatalog.xml") వాడుతాము:

<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<cd>
  <title>Empire Burlesque</title>
  <artist>Bob Dylan</artist>
  <country>USA</country>
  <company>Columbia</company>
  <price>10.90</price>
  <year>1985</year>
</cd>
<cd>
  <title>Hide your heart</title>
  <artist>Bonnie Tyler</artist>
  <country>UK</country>
  <company>CBS Records</company>
  <price>9.90</price>
  <year>1988</year>
</cd>
<cd>
  <title>Greatest Hits</title>
  <artist>Dolly Parton</artist>
  <country>USA</country>
  <company>RCA</company>
  <price>9.90</price>
  <year>1982</year>
</cd>
<cd>
  <title>Still got the blues</title>
  <artist>Gary Moore</artist>
  <country>UK</country>
  <company>Virgin records</company>
  <price>10.20</price>
  <year>1990</year>
</cd>
<cd>
  <title>Eros</title>
  <artist>Eros Ramazzotti</artist>
  <country>EU</country>
  <company>BMG</company>
  <price>9.90</price>
  <year>1997</year>
</cd>
</catalog>

ఈ XML ఫైలును చూడండి:cdcatalog.xml

మొదట, "System.Data" నామకరణంని దిగుమతి చేయండి. ఈ నామకరణం మరియు DataSet ఆబ్జెక్ట్ని సహకరించుటకు అవసరం. .aspx పేజీ పైన క్రింది ఆదేశాన్ని చేర్చండి:

<%@ Import Namespace="System.Data" %>

ఈ XML ఫైల్ని ఒక DataSet కోసం సృష్టించి, ఈ XML ఫైల్ని పేజీ మొదటి లోడ్ సమయంలో DataSet లోకి లోడ్ చేస్తాము:

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
  dim mycdcatalog=New DataSet
  mycdcatalog.ReadXml(MapPath("cdcatalog.xml"))
end if
end sub

అప్పుడు, .aspx పేజీలో ఒక రిపీటర్ కంట్రోల్ సృష్టించి, <HeaderTemplate> అంశంలో ఉన్న విషయం అవుట్పుట్లో ఒకే సారి ప్రదర్శించబడుతుంది, <ItemTemplate> అంశంలో ఉన్న విషయం DataSet లోని "record" విషయాన్ని పునరావృతం చేస్తుంది, చివరగా, <FooterTemplate> అంశంలో ఉన్న విషయం అవుట్పుట్లో ఒకే సారి ప్రదర్శించబడుతుంది:

<html>
<body>
<form runat="server">
<asp:Repeater id="cdcatalog" runat="server">
<HeaderTemplate>
...
</HeaderTemplate>
<ItemTemplate>
...
</ItemTemplate>
<FooterTemplate>
...
</FooterTemplate>
</asp:Repeater>
</form>
</body>
</html>

అప్పుడు మేము DataSet సృష్టించి, ఈ mycdcatalog DataSet ను రిపీటర్ కంట్రోల్కు బైండ్ చేస్తాము. మేము కూడా HTML టాగ్లను ఉపయోగించి ఈ రిపీటర్ కంట్రోల్ను నింపి, <%#Container.DataItem("fieldname")%> పద్ధతి ద్వారా డేటా అంశాన్ని <ItemTemplate> భాగంలో జోడిస్తాము:

<%@ Import Namespace="System.Data" %>
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
  dim mycdcatalog=New DataSet
  mycdcatalog.ReadXml(MapPath("cdcatalog.xml"))
  cdcatalog.DataSource=mycdcatalog
  cdcatalog.DataBind()
end if
end sub
</script>
<html>
<body>
<form runat="server">
<asp:Repeater id="cdcatalog" runat="server">
<HeaderTemplate>
<table border="1" width="100%">
<tr>
<th>Title</th>
<th>Artist</th>
<th>Country</th>
<th>Company</th>
<th>Price</th>
<th>Year</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Container.DataItem("title")%></td>
<td><%#Container.DataItem("artist")%></td>
<td><%#Container.DataItem("country")%></td>
<td><%#Container.DataItem("company")%></td>
<td><%#Container.DataItem("price")%></td>
<td><%#Container.DataItem("year")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</form>
</body>
</html>

ఈ ఉదాహరణను చూపుము

ఆల్టర్నేటింగ్ టెంప్లేట్> ఉపయోగించండి

మీరు <ItemTemplate> అంశం తర్వాత <AlternatingItemTemplate> అంశం జోడించవచ్చు, అలాగే ఆల్టర్నేటింగ్ పంక్తుల రూపాన్ని పరిచయం చేయవచ్చు. దిగువని ఉదాహరణలో, పట్టికలో ప్రతి పంక్తిని హైలైట్ రెడ్ బ్యాక్గ్రౌండ్ ప్రదర్శించబడుతుంది:

<%@ Import Namespace="System.Data" %>
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
  dim mycdcatalog=New DataSet
  mycdcatalog.ReadXml(MapPath("cdcatalog.xml"))
  cdcatalog.DataSource=mycdcatalog
  cdcatalog.DataBind()
end if
end sub
</script>
<html>
<body>
<form runat="server">
<asp:Repeater id="cdcatalog" runat="server">
<HeaderTemplate>
<table border="1" width="100%">
<tr>
<th>Title</th>
<th>Artist</th>
<th>Country</th>
<th>Company</th>
<th>Price</th>
<th>Year</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Container.DataItem("title")%></td>
<td><%#Container.DataItem("artist")%></td>
<td><%#Container.DataItem("country")%></td>
<td><%#Container.DataItem("company")%></td>
<td><%#Container.DataItem("price")%></td>
<td><%#Container.DataItem("year")%></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr bgcolor="#e8e8e8">
<td><%#Container.DataItem("title")%></td>
<td><%#Container.DataItem("artist")%></td>
<td><%#Container.DataItem("country")%></td>
<td><%#Container.DataItem("company")%></td>
<td><%#Container.DataItem("price")%></td>
<td><%#Container.DataItem("year")%></td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</form>
</body>
</html>

ఈ ఉదాహరణను చూపుము

సెపరేటర్ టెంప్లేట్> ఉపయోగించండి

సెపరేటర్ టెంప్లేట్> అంశం ప్రతి రికార్డ్ మధ్య విభజకం పరిచయం చేయటానికి ఉపయోగించబడుతుంది. దిగువని ఉదాహరణలో, పట్టిక పంక్తుల మధ్య ఒక హోరిజంటల్ లైన్ ప్రవేశపెడుతుంది:

<%@ Import Namespace="System.Data" %>
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
  dim mycdcatalog=New DataSet
  mycdcatalog.ReadXml(MapPath("cdcatalog.xml"))
  cdcatalog.DataSource=mycdcatalog
  cdcatalog.DataBind()
end if
end sub
</script>
<html>
<body>
<form runat="server">
<asp:Repeater id="cdcatalog" runat="server">
<HeaderTemplate>
<table border="0" width="100%">
<tr>
<th>Title</th>
<th>Artist</th>
<th>Country</th>
<th>Company</th>
<th>Price</th>
<th>Year</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Container.DataItem("title")%></td>
<td><%#Container.DataItem("artist")%></td>
<td><%#Container.DataItem("country")%></td>
<td><%#Container.DataItem("company")%></td>
<td><%#Container.DataItem("price")%></td>
<td><%#Container.DataItem("year")%></td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td colspan="6"><hr /></td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</form>
</body>
</html>

ఈ ఉదాహరణను చూపుము