banner ad
We are excited to announce that the ASP.NET Forums are moving to the new Microsoft Q&A experience. Learn more >
ASP.NET Forums/Retired Forums/Community Starter Kit (RETIRED)/HOWTO: Create webboxes that display random content

HOWTO: Create webboxes that display random content RSS

4 replies

Last post Jul 01, 2004 05:47 AM by euroiranian

  • kanati kanati

    None

    0 Points

    141 Posts

    Re: HOWTO: Create webboxes that display random content

    Sep 05, 2003 04:28 PM|kanati|LINK

    You could also use the information at this link http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=320029 to make the content section specific!
  • kanati kanati

    None

    0 Points

    141 Posts

    Re: HOWTO: Create webboxes that display random content

    Sep 10, 2003 12:04 PM|kanati|LINK

    There was an error in the SP for step 2 the correct SP is: CREATE PROCEDURE dbo.Community_GetRandomContent ( @communityID int, @pageTypeName NVarchar(50) ) AS DECLARE @pageType INT DECLARE @rand_num INT DECLARE @num_recs INT DECLARE @content_page_id INT -- Get Random Number from number of records SET @pageType = dbo.Community_GetPageTypeFromName(@pageTypeName) DECLARE @currentDate DateTime SET @currentDate = GetUtcDate() SELECT @num_recs = COUNT(*) FROM dbo.Community_GetContentItem(@communityID, 0, @currentDate) Content JOIN Community_ContentPages CP ON Content.ContentPage_ID = CP.ContentPage_ID WHERE CP.ContentPage_PageType = @pageType AND dbo.Community_IsContentVisible(CP.ContentPage_ModerationStatus, CP.ContentPage_DateVisible, GetUtcDate() ) = 1 AND dbo.Community_IsContentPublic(@communityID, CP.ContentPage_SectionID) = 1 -- Select a random number between 1 and the number -- of records in our table SET @rand_num = ROUND(@num_recs * RAND() + 1, 0, 1) -- Create a local, static, read-only, scrollable cursor -- Needs scrollable to use fetch absolute, otherwise we -- would use forward-only declare #mycursor cursor scroll static read_only for SELECT CP.ContentPage_ID FROM dbo.Community_GetContentItem(@communityID, 0, @currentDate) Content JOIN Community_ContentPages CP ON Content.ContentPage_ID = CP.ContentPage_ID WHERE CP.ContentPage_PageType = @pageType AND dbo.Community_IsContentVisible(CP.ContentPage_ModerationStatus, CP.ContentPage_DateVisible, GetUtcDate() ) = 1 AND dbo.Community_IsContentPublic(@communityID, CP.ContentPage_SectionID) = 1 open #mycursor fetch absolute @rand_num from #mycursor into @content_page_id close #mycursor deallocate #mycursor -- Select the columns from the table joined for the key -- selected from the cursor SELECT * FROM dbo.Community_GetContentItem(@communityID, 0, @currentDate) Content JOIN Community_ContentPages CP ON Content.ContentPage_ID = CP.ContentPage_ID WHERE Content.ContentPage_ID = @content_page_id
  • daveranck daveranck

    Member

    20 Points

    102 Posts

    Re: HOWTO: Create webboxes that display random content

    Sep 10, 2003 12:50 PM|daveranck|LINK

    Thanks Kanati! I'm going to incoroporate this and the section-specific content mod. It also lays the ground work for another mod I will add: Content Item of the Day. I want to show a "Tip of the day" web box which points to an article. I can use your code and instructions as the basis for that. Thanks for posting it! Dave Ranck
    Dave Ranck
    Whatever your hand finds to do, do it with all your might
    www.fitnessforeveryman.com
    everymansfitness.wordpress.com
  • euroiranian euroiranian

    None

    0 Points

    67 Posts

    Re: HOWTO: Create webboxes that display random content

    Jul 01, 2004 05:47 AM|euroiranian|LINK

    Hi Kanati, First at all thanks. It doesn't work for me. Why? I followed the three steps correctly, but I got a bank box without data. I only changed: ContentList.DataSource = ContentPageUtility.GetRandomContent("Article"); by ContentList.DataSource = ContentPageUtility.GetRandomContent("PhotoGallery"); Please, may you can give me some help.
  • ‹ Previous Thread|Next Thread ›