Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Random Rows with the DataPager and ListView? (http://www.velocityreviews.com/forums/t641995-random-rows-with-the-datapager-and-listview.html)

MU 10-28-2008 01:13 PM

Random Rows with the DataPager and ListView?
 
Hello

I would like to implement a datapager control on my listview and
return the rows randomly. I am returning the rows with:
ORDER BY NEWID()
which gives me randomized rows but when used with the datapager, when
the user clicks on the Next button, the rows are returned randomized
again, giving me rows that were on the first page.

Is there a way to use the original random dataset instead of it
randomizing again each time the user clicks Next?

Thanks!
MU

Cowboy \(Gregory A. Beamer\) 10-28-2008 01:47 PM

Re: Random Rows with the DataPager and ListView?
 
Sure. You cache the dataset you originally retrieved and create a custom
pager. If you are generating IDs, you will have to make sure those ids are
added to your data objects (DataSet, LINQ, etc.). There are probably other
ways to skin this cat, as well.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
"MU" <michael@lonelyprogrammer.com> wrote in message
news:405c661b-77be-4fac-b4a5-035840b465c1@8g2000hse.googlegroups.com...
> Hello
>
> I would like to implement a datapager control on my listview and
> return the rows randomly. I am returning the rows with:
> ORDER BY NEWID()
> which gives me randomized rows but when used with the datapager, when
> the user clicks on the Next button, the rows are returned randomized
> again, giving me rows that were on the first page.
>
> Is there a way to use the original random dataset instead of it
> randomizing again each time the user clicks Next?
>
> Thanks!
> MU



thealps 06-20-2013 10:31 PM

Can you provide any sample code for this? im working in C#/asp.net 3.5 and using an UpdatePanel and a SqlDataSource to spew out results in a ListView control with a DataPager control. What should seemingly be a simple task isnt so. I want to randomly show results in the dataset from my sql call with ORDER BY NewID() and then have the pager only page with the results from *that* query and not randomize every next/prev page

Thanks!

Chris

Quote:

Originally Posted by Cowboy \(Gregory A. Beamer\) (Post 3663305)
Sure. You cache the dataset you originally retrieved and create a custom
pager. If you are generating IDs, you will have to make sure those ids are
added to your data objects (DataSet, LINQ, etc.). There are probably other
ways to skin this cat, as well.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA


********************************************
| Think outside the box! |
********************************************
"MU" <michael@lonelyprogrammer.com> wrote in message
news:405c661b-77be-4fac-b4a5-035840b465c1@8g2000hse.googlegroups.com...
> Hello
>
> I would like to implement a datapager control on my listview and
> return the rows randomly. I am returning the rows with:
> ORDER BY NEWID()
> which gives me randomized rows but when used with the datapager, when
> the user clicks on the Next button, the rows are returned randomized
> again, giving me rows that were on the first page.
>
> Is there a way to use the original random dataset instead of it
> randomizing again each time the user clicks Next?
>
> Thanks!
> MU


thealps 06-20-2013 10:37 PM

Here is the code im working with

Code:

<div id="columnsContainer">
    <div class="full-width grey">
    <asp:Panel ID="pnlShowAlbumsHomepage" runat="server" Height="240" Width="960" BackColor="#121B32" BackImageUrl="~/img/bg/bg-fade-drkblue.png" Visible="true">
        <div>
            <div class="blankSeparator4"><!-- --></div>
            <div class="PanelHeader960"><h2 class="LinerNotesHdr">Current releases from BeHip Records</h2></div>
            <div class="clearSep"><!-- --></div>
        <asp:UpdatePanel runat="server" ID="upShowAlbumsHomepage" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:ListView runat="server" ID="lvShowAlbumsHomepage"
                    GroupItemCount="6"
                    DataSourceID="sqlGetCurrentAlbums" DataKeyNames="BHPCollectionID">
                    <LayoutTemplate>
                    <table cellpadding="2" runat="server"
                            id="tblProducts" class="HomePageBoxes">
                        <tr runat="server" id="groupPlaceholder">
                        </tr>
                    </table>
                    <div class="divShowAlbPager">
                        <asp:DataPager runat="server" ID="dpShowAlbumsHomepage" PageSize="6">
                            <Fields>
                            <asp:TemplatePagerField>
                                <PagerTemplate>
                                    <div class="divShowAlbumsHomepagePager">
                                &nbsp;
                                <asp:TextBox ID="CurrentRowTextBox" runat="server"
                                        AutoPostBack="true"
                                        Text="<%# Container.StartRowIndex + 1%>"
                                        Columns="1"
                                        style="text-align:right"
                                        OnTextChanged="CurrentRowTextBox_OnTextChanged" />
                                to
                                <asp:Label ID="PageSizeLabel" runat="server" Font-Bold="true"
                                        Text="<%# Container.StartRowIndex + Container.PageSize > Container.TotalRowCount ? Container.TotalRowCount : Container.StartRowIndex + Container.PageSize %>" />
                                of
                                <asp:Label ID="TotalRowsLabel" runat="server" Font-Bold="true"
                                        Text="<%# Container.TotalRowCount %>" />
                                        </div>
                                </PagerTemplate>
                            </asp:TemplatePagerField>
                            <asp:NextPreviousPagerField ButtonCssClass="divShowAlbumsHomepagePager"
                                    ShowFirstPageButton="true" ShowLastPageButton="true"
                                    FirstPageText="<< " LastPageText=" >>"
                                    NextPageText=" > " PreviousPageText=" < " />
                            </Fields>
                        </asp:DataPager>
                    </div>
                    </LayoutTemplate>
                    <GroupTemplate>
                    <tr runat="server" id="productRow"
                        style="height:150px">
                        <td runat="server" id="itemPlaceholder">
                        </td>
                    </tr>
                    </GroupTemplate>
                    <ItemTemplate>
                    <td id="Td1" valign="top" align="center" style="width:150px" runat="server" class="HomePageBoxes">
                        <a href='<%# Page.ResolveClientUrl("~/") + Eval("URLBeHipProfile")%>'><asp:Image ID="imgAlbumImage" runat="server"
                            ImageUrl='<%#"~/img/release-covers/" + Eval("BHPCollectionID") + "_127x127.png" %>'
                            Height="127"  class="poshytip" title='<% #Eval("CollectionName") %>' /></a><br />
                        <asp:HyperLink ID='hlAlbumLink' runat='server' Text='<% #Eval("CollectionName") %>'
                            NavigateUrl='<%#"~/" + Eval("URLBeHipProfile") %>' />
                    </td>
                    </ItemTemplate>
                </asp:ListView>
                <asp:SqlDataSource ID="sqlGetCurrentAlbums" Runat="server"
                            SelectCommand="SELECT * FROM BHPCollections WHERE (isActive = '1') AND (isLive = '1') ORDER BY NewID() "
                            ConnectionString="<%$ ConnectionStrings:conBHP %>">
                </asp:SqlDataSource>
            </ContentTemplate>

        </asp:UpdatePanel>
            </div>
        </asp:Panel>
        <asp:RoundedCornersExtender ID="rceShowAlbumsHomepage" runat="server" TargetControlID="pnlShowAlbumsHomepage" Radius="10" Corners="ALL" />
    </div>
    </div>



All times are GMT. The time now is 08:29 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.