I think I came very close to the solution , but somewhere I missed something.
I am using article selector to display all blog posts to select .Article selector contains a grid which shows all posts.Selected posts are stored in a list (the Value property.)
This can be converted into a string with semi colon separated using type converter.
When I click on the select rad window opens with grid view but there is now submit or cancel button.
After selection , when I close my rad window , OnClientClose event is firing but
sender.argument property is returning null or undefined. How can I get the selected post ids from rad window and set my text box with those ids.
using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;
namespace Telerik.Samples
{
using Cms.Web.UI;
using Framework.Web;
using Web.UI;
using Telerik.Cms.Engine;
using System.Data;
/// <summary>
/// WebEditor control used for editing the items (ListLinks property)
/// of the links list in user friendly manner
/// </summary>
public class ListItemEditor : WebUITypeEditor<List<string>>, IControlPropertyEditor
{
#region Properties
/// <summary>
/// Gets or sets the Value property - Value property represents the property which TypeEditor
/// will edit of the parent control which fired the type editor. In our sample, Value property
/// represents ListLinks property of the LinksList6.ascx user control
/// </summary>
public override List<string> Value
{
get
{
if (listLinks == null)
listLinks = new List<string>();
return listLinks;
}
set
{
listLinks = value;
}
}
/// <summary>
/// Gets or sets the path of the Dialog template
/// </summary>
public string DialogTemplatePath
{
get
{
string value = (string)ViewState["DialogTemplatePath"];
return String.IsNullOrEmpty(value) ? "~/UC/TypeEditorTemplate.ascx" : value;
}
set
{
ViewState["DialogTemplatePath"] = value;
}
}
/// <summary>
/// Gets or sets the Dialog template
/// </summary>
public ITemplate DialogTemplate
{
get
{
dialogTemplate = ControlUtils.GetTemplate<DefaultDialogTemplate>(DialogTemplatePath);
return dialogTemplate;
}
set
{
dialogTemplate = value;
}
}
/// <summary>
/// Returns a dictionary with the dependent properties
/// </summary>
/// <remarks>
/// DependentProperties property allows us to modify additional properties
/// (not just the value of the property which fired TypeEditor) of the control which
/// has called TypeEditor. In this sample we will modify LinkTarget property in addition
/// to ListLinks property which is represented through ValueProperty of this control.
/// </remarks>
public IDictionary<string, object> DependentProperties
{
get
{
if (dependentProps == null)
{
dependentProps = new Dictionary<string, object>();
//dependentProps.Add("LinkTarget", linkTarget);
}
return dependentProps;
}
}
/// <summary>
/// First time to Bind grid
/// </summary>
public bool IsGridLoadedFirstTime
{
get
{
if (ViewState["IsGridLoadedFirstTime"] == null)
return true;
return false;
}
set
{
ViewState["IsGridLoadedFirstTime"] = value;
}
}
public SortDirection GridViewSortDirection
{
get
{
if (ViewState["sortDirection"] == null)
ViewState["sortDirection"] = SortDirection.Ascending;
return (SortDirection)ViewState["sortDirection"];
}
set
{
ViewState["sortDirection"] = value;
}
}
public string GridViewSortBy
{
get
{
if (ViewState["GridViewSortBy"] == null)
ViewState["GridViewSortBy"] = "Title";
return (string)ViewState["GridViewSortBy"];
}
set
{
ViewState["GridViewSortBy"] = value;
}
}
#endregion
#region Methods
/// <summary>
/// Overriden. Cancels the rendering of a beginning HTML tag for the control.
/// </summary>
/// <param name="writer">The HtmlTextWriter object used to render the markup.</param>
public override void RenderBeginTag(HtmlTextWriter writer)
{
// Do not render begin tag
}
/// <summary>
/// Overriden. Cancels the rendering of an ending HTML tag for the control.
/// </summary>
/// <param name="writer">The HtmlTextWriter object used to render the markup.</param>
public override void RenderEndTag(HtmlTextWriter writer)
{
// Do not render end tag
}
/// <summary>
/// Overrides the base method and registers ControlDesignerBase control as one whose control state
/// must be persisted.
/// </summary>
/// <param name="e"></param>
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (Page != null)
Page.RegisterRequiresControlState(this);
}
/// <summary>
/// Restores control state information from a previous page request that was saved by the SaveControlState
/// method.
/// </summary>
/// <param name="savedState">Represents the control state to be restored.</param>
protected override void LoadControlState(object savedState)
{
if (savedState != null)
{
object[] state = (object[])savedState;
listLinks = (List<string>)state[0];
}
}
/// <summary>
/// Saves server control state changes.
/// </summary>
/// <returns></returns>
protected override object SaveControlState()
{
return new object[] {
listLinks
};
}
/// <summary>
/// Overriden. Called to populate the child control hierarchy. This is the main
/// method to render the control's markup, since it is a CompositeControl and contains
/// child controls.
/// </summary>
protected override void CreateChildControls()
{
// initialize the container and template
dialogContainer = new Container(this);
DialogTemplate.InstantiateIn(dialogContainer);
dialogContainer.FilterByDropDownList.AutoPostBack = true;
dialogContainer.FilterByDropDownList.SelectedIndexChanged += new EventHandler(FilterByDropDownList_SelectedIndexChanged);
dialogContainer.FilterItemsDropDownList.AutoPostBack = true;
dialogContainer.FilterItemsDropDownList.SelectedIndexChanged += new EventHandler(FilterItemsDropDownList_SelectedIndexChanged);
dialogContainer.BlogPostsGrid.RowDataBound += new GridViewRowEventHandler(BlogPostsGrid_RowDataBound);
dialogContainer.BlogPostsGrid.Sorting+=new GridViewSortEventHandler(BlogPostsGrid_Sorting);
dialogContainer.BlogPostsGrid.PageIndexChanging += new GridViewPageEventHandler(BlogPostsGrid_PageIndexChanging);
dialogContainer.BlogPostsGrid.RowCommand += new GridViewCommandEventHandler(BlogPostsGrid_RowCommand);
Controls.Add(dialogContainer);
if (IsGridLoadedFirstTime)
{
BindFilterItemsDropDownList();
IList selectedBlogs = contentManager.GetContent(0, 0, "Publication_Date " + sortExpression);
BindBlogPosts(selectedBlogs);
IsGridLoadedFirstTime = false;
}
}
void BlogPostsGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
string select = "select";
string unselect = "unselect";
LinkButton sourceBtn = e.CommandSource as LinkButton;
if (e.CommandName == select)
{
if (Value != null && !Value.Contains((string)e.CommandArgument))
{
Value.Add((string)e.CommandArgument);
sourceBtn.CommandName = unselect;
sourceBtn.Text = unselect;
OnValueChanged(new ValueChangedEventArgs(this.Value));
}
}
else
{
if (Value != null && Value.Contains((string)e.CommandArgument))
{
Value.Remove((string)e.CommandArgument);
sourceBtn.CommandName = select;
sourceBtn.Text = select;
OnValueChanged(new ValueChangedEventArgs(this.Value));
}
}
}
void BlogPostsGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GetBlogPostsAndBind(GridViewSortBy,ConvertSortDirectionToSql(GridViewSortDirection));
dialogContainer.BlogPostsGrid.PageIndex = e.NewPageIndex;
dialogContainer.BlogPostsGrid.DataBind();
}
void BlogPostsGrid_Sorting(object sender, GridViewSortEventArgs e)
{
if (GridViewSortBy != e.SortExpression)
{
GridViewSortDirection = SortDirection.Ascending;
GridViewSortBy = e.SortExpression;
}
else
{
if (GridViewSortDirection == SortDirection.Ascending)
{
GridViewSortDirection = SortDirection.Descending;
}
else
{
GridViewSortDirection = SortDirection.Ascending;
}
}
GetBlogPostsAndBind(GridViewSortBy,ConvertSortDirectionToSql(GridViewSortDirection));
}
#endregion
#region Private methods
private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;
switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = " ASC";
break;
case SortDirection.Descending:
newSortDirection = " DESC";
break;
}
return newSortDirection;
}
private void BindBlogPosts(IList selectedBlogs)
{
dialogContainer.BlogPostsGrid.DataSource = selectedBlogs;
dialogContainer.BlogPostsGrid.DataBind();
}
private void BindFilterItemsDropDownList()
{
if (dialogContainer.FilterByDropDownList.SelectedValue == "All")
{
dialogContainer.FilterItemsDropDownList.Visible = false;
dialogContainer.SelectTagOrCategoryLiteral.Visible = false;
return;
}
dialogContainer.FilterItemsDropDownList.Visible = true;
dialogContainer.SelectTagOrCategoryLiteral.Visible = true;
if (dialogContainer.FilterByDropDownList.SelectedValue == "Category")
{
dialogContainer.SelectTagOrCategoryLiteral.Text = "Select a Category:";
// create a list of all categories
IList listOfCategories = contentManager.GetCategories();
if (listOfCategories.Count > 0)
{
dialogContainer.FilterItemsDropDownList.Items.Clear();
foreach (Telerik.Cms.Engine.ICategory catItem in listOfCategories)
{
ListItem item = new ListItem(catItem.CategoryName, catItem.ID.ToString());
dialogContainer.FilterItemsDropDownList.Items.Add(item);
}
}
}
else
{
dialogContainer.SelectTagOrCategoryLiteral.Text = "Select a Tag:";
// create a list of all categories
IList listOfTags = contentManager.GetTags();
if (listOfTags.Count > 0)
{
dialogContainer.FilterItemsDropDownList.Items.Clear();
foreach (Telerik.Cms.Engine.ITag tagItem in listOfTags)
{
ListItem item = new ListItem(tagItem.TagName, tagItem.ID.ToString());
dialogContainer.FilterItemsDropDownList.Items.Add(item);
}
}
}
dialogContainer.FilterItemsDropDownList.Items.Insert(0,new ListItem("All","All"));
dialogContainer.FilterItemsDropDownList.SelectedIndex = 0;
if (!IsGridLoadedFirstTime)
{
GetBlogPostsAndBind(GridViewSortBy,sortExpression);
}
}
private void GetBlogPostsAndBind(string sortBy,string sortExpression)
{
if (dialogContainer.FilterByDropDownList.SelectedValue == "All" || (dialogContainer.FilterItemsDropDownList.SelectedItem != null && dialogContainer.FilterItemsDropDownList.SelectedItem.Text == "All"))
{
IList selectedBlogs = contentManager.GetContent(0, 0, sortBy + sortExpression);
BindBlogPosts(selectedBlogs);
return;
}
if (dialogContainer.FilterByDropDownList.SelectedValue == "Category")
{
List<IMetaSearchInfo> publicationFilters = new List<IMetaSearchInfo>();
MetaSearchInfo filter1 = new MetaSearchInfo(MetaValueTypes.ShortText, "Category", dialogContainer.FilterItemsDropDownList.SelectedItem.Text, SearchCondition.Like);
publicationFilters.Add(filter1);
IList selectedBlogs = contentManager.GetContent(sortBy + sortExpression, publicationFilters.ToArray());
BindBlogPosts(selectedBlogs);
}
else
{
IList selectedBlogs = contentManager.GetContent(0, 0, sortBy + sortExpression, dialogContainer.FilterItemsDropDownList.SelectedItem.Text);
BindBlogPosts(selectedBlogs);
}
}
#endregion
#region Event handlers
void FilterItemsDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
GetBlogPostsAndBind(GridViewSortBy,sortExpression);
}
void BlogPostsGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
IContent content = e.Row.DataItem as IContent;
if (content != null)
{
string title= (string)content.GetMetaData("Title");
Literal litTitle = e.Row.FindControl("litTitle") as Literal;
Literal litDate = e.Row.FindControl("litDate") as Literal;
litDate.Text = string.Format("{0:dd/MM/yy}",content.GetMetaData("Publication_Date"));
LinkButton lnkBtnSelect = e.Row.FindControl("lnkBtnSelect") as LinkButton;
if (listLinks !=null && listLinks.Contains(content.ID.ToString()))
{
lnkBtnSelect.Text = unselect;
lnkBtnSelect.CommandName = unselect;
}
else
{
lnkBtnSelect.Text = select;
lnkBtnSelect.CommandName = select;
}
litTitle.Text = title;
}
}
}
private void FilterByDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
BindFilterItemsDropDownList();
}
#endregion
#region Private Propeties
private List<string> listLinks;
private string sortExpression = " ASC";
//private string linkTarget;
private ITemplate dialogTemplate;
private Container dialogContainer;
private Dictionary<string, object> dependentProps;
private bool isGridBinded = false;
string select = "select";
string unselect = "unselect";
Telerik.Cms.Engine.ContentManager contentManager = new Telerik.Cms.Engine.ContentManager("Blogs");
#endregion
#region Default Templates
/// <summary>
/// Class which defines the template for this control, in case template has not been
/// defined through an external file or through inline declaration
/// </summary>
private class DefaultDialogTemplate : ITemplate
{
public void InstantiateIn(Control container)
{
throw new Exception("Default template for LinksListItemEditor has not been implemented.");
}
}
#endregion
#region Containers
/// <summary>
/// Class which provides easy, strongly-typed access to the child controls defined in a template
/// regardless of their position in the child control hierarchy
/// </summary>
private class Container : GenericContainer<ListItemEditor>
{
public Container(ListItemEditor owner)
: base(owner)
{
}
public GridView BlogPostsGrid
{
get
{
if (blogPostsGrid == null)
blogPostsGrid = FindRequiredControl<GridView>("postListGrid");
return blogPostsGrid;
}
}
public DropDownList FilterByDropDownList
{
get
{
if (filterByDropDownList == null)
filterByDropDownList = FindRequiredControl<DropDownList>("ddlFilterBy");
return filterByDropDownList;
}
}
public DropDownList FilterItemsDropDownList
{
get
{
if (filterItemsDropDownList == null)
filterItemsDropDownList = FindRequiredControl<DropDownList>("ddlItems");
return filterItemsDropDownList;
}
}
public Literal SelectTagOrCategoryLiteral
{
get
{
if (selectTagOrCategoryLiteral == null)
selectTagOrCategoryLiteral = FindRequiredControl<Literal>("litSelectTagOrCategory");
return selectTagOrCategoryLiteral;
}
}
private Repeater blogPostsRepeater;
private GridView blogPostsGrid;
private DropDownList filterByDropDownList;
private DropDownList filterItemsDropDownList;
private Literal selectTagOrCategoryLiteral;
}
#endregion
}
}