Audio Video Modules for ASP.NET Community Starter Kit : Part III

Implement the page for listing all section contents.

We use this page to display all contents of an audio-video section. We have create minimum a skin and the control class to control the skin.

Skin:
\Communities\Common\Themes\Default\Skins\ContentSkins \AudioVideos_AudioVideoSection.ascx

Control class : The  "AudioVideoSection" class , which is derived from the "ContentListPage" class, acts as code-behind for this particular skin. (see figure 6). Note that we have initialized the inherited attributes _skinFileName and _getContentItems. From now, the " ContentListPage" class and its ancestor "SkinnedCommunityControle" class will take over most burden jobs such like populating ContentListPage.

ContentList from us. We must only reuse or create custom controls which can be embedded as ItemTemplate in the "ContentList" instance.

namespace ASPNET.StarterKit.Communities.AudioVideos
{
using
System;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
ASPNET.StarterKit.Communities;
//*********************************************************************
//
// AudioVideoSection Class
//
// Represents the default page for the Audio-Video section. This class
// displays a list of audio video listings.
//
// _skinFileName = the name of the skin to use for this section
//
// _getContentItems = the name of the method that retrieves the list of content items
//
//*********************************************************************
public class
AudioVideoSection : ContentListPage
{
string
_skinFileName = "AudioVideos_AudioVideoSection.ascx";
GetContentItemsDelegate _getContentItems =
new
GetContentItemsDelegate
AudioVideoUtility.GetAllAudioVideos);
//*********************************************************************
//
// AudioVideoSection Constructor
//
// Assigns skin and contentItems method to base ContentListPage class
//
//*********************************************************************
public AudioVideoSection() : base
()
{
SkinFileName = _skinFileName;
GetContentItems = _getContentItems;
}
}


Figure 6 (The AudioVideoSection class)

We have created "ItemAVTitle" class  to represent the title of an Audio-Video content. It will display the title of a particular content and a image link to represent the type of the content(Audio or Video).

namespace ASPNET.StarterKit.Communities
{
using
System;
using
System.Web;
using
System.Text;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Text.RegularExpressions;
using
ASPNET.StarterKit.Communities.Books;
//*********************************************************************
//
// ItemAVTitle Class
//
// Represents a audiovideo Title in a ContentList template
//
//*********************************************************************
public class
ItemAVTitle : WebControl
{
private string
_externalIconsrc="~/Communities/Common/Images/Video.gif";
//*********************************************************************
//
// ItemLinkTitle Constructor
//
// Assign a default css style (the user can override)
//
//*********************************************************************
public
ItemAVTitle()
{
CssClass = "itemLinkTitle";
EnableViewState =
false
;

//*********************************************************************
//
// ExternalIconSrc Property
//
// Allows users to assign a custom icon for external links
//
//*********************************************************************
public string
ExternalIconSrc
{
get { return
_externalIconSrc; }
set { _externalIconSrc = value
; }
}
//*********************************************************************
//
// ContentPageID Property
//
// Represents the contentpageID of the item
//
//*********************************************************************
public int
ContentPageID
{
get
{
if (ViewState["ContentPageID"] == null
)
return
-1;
else
return (int
)ViewState["ContentPageID"];
}
set
{
ViewState["ContentPageID"] =
value
;
}
}
//*********************************************************************
//
//Title Property
//
// Represents the Title of the item
//
//*********************************************************************
public string
Title
{
get
{
if (ViewState["Title"] == null
)
return
String.Empty;
else
return (string
)ViewState["Title"];
}
set
{
ViewState["Title"] =
value
;
//*********************************************************************
//
// OnDataBinding Method
//
// Get the title from the container's DataItem property
//
//*********************************************************************
override protected void
OnDataBinding(EventArgs e)
{
ContentItem item;
if (NamingContainer is
ContentItem)
item = (ContentItem)NamingContainer;
else
item = (ContentItem)NamingContainer.NamingContainer;
AudioVideoInfo objAVInfo = (AudioVideoInfo)item.DataItem;
ContentPageID = objAVInfo.ContentPageID;
Title=objAVInfo.Title;
// Fix the icon depend from the content
if(objAVInfo.Video!=true
)
{
_externalIconsrc="~/Communities/Common/Images/Audio.gif";
}
}
///
<summary>
///
compose the visual representation
///
</summary>
override protected void
CreateChildControls()
{
// Image Link
HyperLink hlImgBroadcast = new
HyperLink();
hlImgBroadcast.ImageUrl=Page.ResolveUrl(_externalIconSrc);
hlImgBroadcast.Text=Title;
string
strRedirect=CommunityGlobals.CalculatePath(String.Format"{0}.aspx",ContentPageID));
hlImgBroadcast.NavigateUrl=strRedirect;
this
.Controls.Add(hlImgBroadcast);
// gap
LiteralControl lControl=new
LiteralControl("&nbsp;&nbsp;");
this
.Controls.Add(lControl);
// Text Link
HyperLink hlBroadcast = new
HyperLink();
hlBroadcast.Text=Title;
hlBroadcast.NavigateUrl=strRedirect;
this
.Controls.Add(hlBroadcast);

}
}


Figure 7 ( Source code for the ItemAVTitle class )

Additionally, we have created an another custom control "AudioVideoEditControl" (figure 7)  which is used to navigate to other related pages from section page.

using System.ComponentModel;
namespace
ASPNET.StarterKit.Communities
{
using
System;
[Designer(
typeof
(ASPNET.StarterKit.Communities.CommunityDesigner))]
public class
AudioVideoEditContent : EditContent
{
///
<summary>
///
This class is used to as Navigator
///
and this control is embedded in AudioVideoSecton.ascx
///
</summary>
public
AudioVideoEditContent()
{
if (Context != null
)
{
PageInfo _pageInfo = (PageInfo)Context.Items["PageInfo"];
int
contentPageID = _pageInfo.ID;
AddUrl = "AudioVideos_AddAudioVideo.aspx";
EditUrl = String.Format("AudioVideos_EditAudioVideo.aspx?id={0}", contentPageID);
DeleteUrl = String.Format("ContentPages_DeleteContentPage.aspx?id={0}", contentPageID);
MoveUrl = String.Format("ContentPages_MoveContentPage.aspx?id={0}",
ontentPageID);
CommentUrl = String.Format("Comments_AddComment.aspx?id={0}", contentPageID);
ModerateUrl = "Moderation_ModerateSection.aspx";
}
}
}


Figure 7

Finally , we must register this page as section page using the following the statement

/* registers AudioVideoSection as section PageType*/
IF NOT EXISTS (SELECT * FROM Community_PageTypes WHERE pageType_Name='AudioVideoSection')
BEGIN
INSERT INTO Community_PageTypes
(
pageType_Name,
pageType_Description,
pageType_PageContent,
pageType_isSectionType
)
VALUES
(
'AudioVideoSection',
'Contains AudioVideo listings',
'ASPNET.StarterKit.Communities.AudioVideos.AudioVideoSection',
1
)
END
Go

continue article

Up Next
    Ebook Download
    View all
    Learn
    View all