Loading recordsets, 4 elements at a time

I have a question about loading slideshow recordsets on my home page. I am using ASP.NET, LINQ and C #.

This is the markup for 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>

      

Each "slide" must contain 4 elements. Therefore, I need to create sets with records that contain max. 4 entries. 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 anyone help me?

+3


source to share


2 answers


first you can load all the images in the array. then check the reminder at 4 if the reminder is zero for reorganizing images in another array. finally, traverse the new array to show the slide.

you can get a 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.

0


source


Skip and Take can help you here.

Let's say you have all the elements of a variable 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);

      

0


source







All Articles