3

I've a question about loading sets of records for a 'slideshow' on my homepage. I'm using ASP.NET, LINQ and C#.

This is the markup of the repeater:

<asp:Repeater ID="rptSlideShow" runat="server">
    <ItemTemplate>
        <div class="slide">
            <nav>
                <ul>
                    <li>
                        <a href="#">
                            <img src="Content/Images/logo-artica.gif" alt="ARTICA PRODUCTIONS" width="154" height="82" /></a>
                    </li>
                    <li>
                        <a href="#">
                            <img src="Content/Images/logo-nead.gif" alt="NEAD A GOOD STORY" width="233" height="70" /></a>
                    </li>
                    <li>
                        <a href="#">
                            <img src="Content/Images/logo-garden.gif" alt="YOUR GARDEN" width="250" height="90" /></a>
                    </li>
                    <li>
                        <a href="#">
                            <img src="Content/Images/logo-bitmap.gif" alt="Bitmap" width="48" height="54" /></a>
                    </li>
                </ul>
            </nav>
        </div>
    </ItemTemplate>
</asp:Repeater>

Every 'slide' should contain 4 items. So I need to build sets with records that contain max. 4 records. If for example the last set contains only 2, because there are no more records, it needs to start over and get 2 items from the beginning.

Is this doable in C#?

Can someone help me with this?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Daniel Plomp
  • 174
  • 1
  • 12

2 Answers2

0

at first you can load all the images in an array. then check the reminder by 4 whether reminder becomes zero to reorganize the images in another array. finally traverse the new array to show the slide.

you may get hint from below:

int[] arr;
// load all images
arr[0]="element0";
arr[1]="element1";
arr[2]="element2";
arr[3]="element3";
arr[4]="element4";
arr[5]="element5";
arr[6]="element6";
arr[7]="element7";
arr[8]="element8";
arr[9]="element9";

int newLength=0;
int count=0;
int reminder=0;

if(arr.length%4!=0){
reminder=(arr.length%4)
newLength=arr.length+reminder
}

int[] nArr=new int[newLength];

for(int i=0;i<arr.length;i++){
count++;
nArr[i]=arr[i];
if(i==arr.length-1){
int rem=nArr.length-arr.length;
for(int j=0;j<rem;j++){
nArr[count]=arr[j];
count++;
}
}
}

Hope this helps, thanks.

Rashedul.Rubel
  • 3,446
  • 25
  • 36
0

Skip and Take can help you out here.

Lets say you have all the elements in a variable called listOfElements

you could do something like this -

For the first page

var firstPageItems = listOfElements.Take(4);

For the n'th page

var nthPageItems = list.Skip(n*4).Take(4);
Srikanth Venugopalan
  • 9,011
  • 3
  • 36
  • 76