Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
1.57/5 (3 votes)
See more:
Hi,

I want display 1st even record and 1st odd record, 2nd even record and 2nd odd record ...etc in a repeater. I want pagenation also.

This is my code:
ASP.NET
<asp:Repeater ID="Repeater1" runat="server">
                <ItemTemplate>
                first div start.........
                    <div class="item thumbnail">
                        <div class="art-im">
                            <a href="/Articles.aspx?Id=<%# Eval("Id")%>">
                                <asp:Image runat="server" Width="240px" Height="135px" ID="smr" Style="margin-bottom: 11px;"
                                    ImageUrl='<%#Picture(Eval("PicturePathId"))%>' /></a></div>
                        <div class="art-cont">
                            <div class="art-head-part">
                                <a href="/Articles.aspx?Id=<%# Eval("Id")%>" class="art-cate">
                                    <%# Eval("Title") %></a>
                                <h3 class="art-tit">
                                    <a href="/Articles.aspx?Id=<%# Eval("Id")%>">
                                        <%# Eval("Description").ToString().Substring(0, Math.Min(120, Eval("Description").ToString().Length)) + "...."%></a></h3>
                            </div>
                            <div class="art-foot-part">
                                <a id="imgshare" href="#?w=500" class="poplight1" rel="popupSharev"><span><b>1.3K</b>
                                    SHARES</span> </a>
                            </div>
                        </div>
                    </div>
                    first div end....
                    secon dive start.......
                    <div class="item large">
                        <div class="art-im">
                            <a href="#">
                                <img src="images/job-art-large-img01.png" alt="article" /></a></div>
                        <div class="art-cont">
                            <div class="art-head-part big-cont">
                                <a href="#" class="art-cate">
                                    <%# Eval("Title") %>
                                </a>
                                <asp:Label ID="Label1" runat="server" Text=' <%# Eval("Title") %>'></asp:Label>
                                <h3 class="art-tit">
                                    <a href="#">
                                        <%# Eval("Description") %>
                            </div>
                            <div class="art-foot-part">
                                <a href="#"><span><b>1.3K</b> SHARES</span></a>
                            </div>
                        </div>
                    </div>
                    second div end.....
                </ItemTemplate>
            </asp:Repeater>



I want to first record on first div and second record on second div, again 3rd record on 1st div and 4th record on 2nd div again....etc......

my linq qury is:
var leftdata = from a in context.Blogstabels select a;


Repeater1.DataSource = leftdata;
Repeater1.DataBind();

Please Help me.....

Thank you........
Posted
Updated 14-May-14 0:04am
v5
Comments
syed shanu 14-May-14 4:53am    
Hi i hope your datasource will be from database IF so you can query to select odd records and even records and bind the even recods dataset to 1st repeater and odd result data set to 2nd repeater : here is the sample query to display the odd and even record.

SELECT t.First, t.Last
FROM (
SELECT *, Row_Number() OVER(ORDER BY First, Last) AS RowNumber
--Row_Number() starts with 1
FROM Table1
) t
WHERE t.RowNumber % 2 = 0 --Even
--WHERE t.RowNumber % 2 = 1 --Odd



Chk this link for more details :
http://stackoverflow.com/questions/2997458/how-to-show-only-even-or-odd-rows-in-sql-server-2008
DamithSL 14-May-14 5:14am    
update question with the code where you binding repeater?

As you want to have odd (1,3,5..) records in first div and even (2,4,6..) records in second div, you can use alternate item template "AlternatingItemTemplate" of repeater to accomplish this task by having your first div in "<ItemTemplate>" tag and second div in "<AlternateItemTemplate>" tag of repeater.

I hope this solution would help you..:)
 
Share this answer
 
Comments
NagaRaju Pesarlanka 14-May-14 6:29am    
Thank you very much.
Please give this way of code (1,4,7..) records in first div and (2,5,8..) records in second div and (3,6,9..) records in third div.
Mandip Grewal 15-May-14 5:31am    
For this, you have to write all three divs in "<itemtemplate>" only and make visible any one out of three div depending upon the row number. You can get the row number in <itemtemplate> with "<%# Container.ItemIndex + 1 %>". Please refer the demo provided below:

<asp:Repeater ID="repDemo" runat="server">

<itemtemplate>

<div style='background-color:green;display:<%#(Container.ItemIndex+1)%3==1?";":"none;"%>'><%#Eval("DisplayName") %></div>

<div style='background-color:orange;display:<%#(Container.ItemIndex+1)%3==2?";":"none;"%>'><%#Eval("DisplayName") %></div>


<div style='background-color:yellow;display:<%#(Container.ItemIndex+1)%3==0?";":"none;"%>'><%#Eval("DisplayName") %></div>

</itemtemplate>

</asp:Repeater>
NagaRaju Pesarlanka 16-May-14 1:28am    
very very thanks.....
try like below

C#
var oddData = context.Blogstabels.ToList().Where((c,i) => i % 2 != 0);
var evnData = context.Blogstabels.ToList().Where((c,i) => i % 2 == 0);

Repeater1.DataSource = oddData;
Repeater1.DataBind();

Repeater2.DataSource = evnData;
Repeater2.DataBind();


As per your comment, I think you should use DataList control for your needs. check below
http://msdn.microsoft.com/en-us/library/bb525467.aspx[^]

set the RepeatColumns property to 2 and you will get expected result.

Ref:[^]
 
Share this answer
 
v3
Comments
NagaRaju Pesarlanka 14-May-14 6:01am    
I want sequential order one even and one odd, one even and one odd...etc
DamithSL 14-May-14 6:11am    
Oh, check my update

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900