Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Random Rows with the DataPager and ListView?

Reply
Thread Tools

Random Rows with the DataPager and ListView?

 
 
MU
Guest
Posts: n/a
 
      10-28-2008
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
 
Reply With Quote
 
 
 
 
Cowboy \(Gregory A. Beamer\)
Guest
Posts: n/a
 
      10-28-2008
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
 
thealps thealps is offline
Junior Member
Join Date: Jun 2013
Posts: 2
 
      06-20-2013
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\) View Post
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
 
Reply With Quote
 
thealps thealps is offline
Junior Member
Join Date: Jun 2013
Posts: 2
 
      06-20-2013
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>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Math.random() and Math.round(Math.random()) and Math.floor(Math.random()*2) VK Javascript 15 05-02-2010 03:43 PM
DataPager and ListView with Randomized Rows? MU ASP .Net 0 10-28-2008 02:09 PM
random.random(), random not defined!? globalrev Python 4 04-20-2008 08:12 AM
DataPager and ListView: Custom Datasource Mark Olbert ASP .Net 5 01-09-2008 02:02 AM
DataPager Strange Behavior shapper ASP .Net 0 11-22-2007 01:08 AM



Advertisments