ektron中的模板控制

ektron中的模板控制,ektron,Ektron,我尝试使用分类树检索分类列表,在编辑中,我选择分类并获取分类ID,通过使用分类ID,我希望使用模板控件使用分类过滤器显示数据。我无法检索数据。我正在附加HTML和我所做的代码,因此请帮助我找到解决方案 }如果我正确理解了您的问题,您就拥有分类id并希望显示该分类中的所有内容。如果这不是你想要的,那么请澄清你的问题,我会尽力帮助你 我发现小部件附带的附加功能有时会使测试API和服务器控件的正确使用变得困难。因此,我建议从一个简单的ASPX页面开始 通常,模板化服务器控件的示例显示了设置过滤

我尝试使用分类树检索分类列表,在编辑中,我选择分类并获取分类ID,通过使用分类ID,我希望使用模板控件使用分类过滤器显示数据。我无法检索数据。我正在附加HTML和我所做的代码,因此请帮助我找到解决方案


}

如果我正确理解了您的问题,您就拥有分类id并希望显示该分类中的所有内容。如果这不是你想要的,那么请澄清你的问题,我会尽力帮助你

我发现小部件附带的附加功能有时会使测试API和服务器控件的正确使用变得困难。因此,我建议从一个简单的ASPX页面开始


通常,模板化服务器控件的示例显示了设置过滤器的声明性语法,您可以将过滤器放在ASPX标记中,就在ContentModelSource控件中。比如:


(更多示例和示例。)

但是,对于听起来您想要完成的事情,您需要通过代码定义过滤器。此代码仅用于:

受保护的长分类ID
{
得到
{
长id;
long.TryParse(Request.QueryString[“id”],out-id);
返回id;
}
}
受保护的布尔是安全的
{
得到
{
布尔递归;
bool.TryParse(Request.QueryString[“recursive”],out recursive);
返回递归;
}
}
受保护的无效页_Init(对象发送方,事件参数e)
{
如果(分类ID>0)
{
如果(IsRecursive)
{
var tm=新的分类管理器();
var td=tm.GetItem(分类法ID);
如果(td!=null)
{
var pathFilter=新的ContentTaxonomyFilter();
pathFilter.Field=ContentTaxonomyProperty.Path;
pathFilter.Operator=CriteriaFilterOperator.StartWith;
pathFilter.Value=td.Path;
contentModelSource.TaxonomyFilters.Add(pathFilter);
}
}
其他的
{
var filter=新的ContentTaxonomyFilter();
filter.Field=ContentTaxonomyProperty.Id;
filter.Value=TaxonomyId.ToString();
filter.Operator=criteriafilterooperator.EqualTo;
contentModelSource.TaxonomyFilters.Add(过滤器);
}
}
}
有几件事需要注意:

  • 分类ID是一个属性。我这样做是为了在这个简单的ASPX页面和自定义小部件之间有一个简单的比较点,在自定义小部件中,您的属性将被
    WidgetDataMember
    属性修饰
  • 代码位于Page_Init事件处理程序中。这很重要。页面加载在页面的生命周期中太晚。我假设在小部件的上下文中也是如此
  • IsRecursive==true
    时,我的代码不一定优化。您可以通过以下方式获得合理的性能,但是调用api来获取分类数据,然后使用该数据为内容设置过滤器的想法似乎有点不切实际。理想情况下,ContentTaxonomyFilter将具有“递归”属性

我请求你们给我一些解决方案,我急需。。。。。
    <asp:View ID="View" runat="server">          

    <asp:Label ID="lblID" runat="server"></asp:Label>            
    <CMS:Directory CssClass="taxList" ID="TaxonomySummary1" EnableAjax="true" runat="server"
                EnablePaging="false"  />

          <ektron:ContentModelSource ID="cntModelSourcs" runat="server" OrderByField="DateCreated" 
    OrderByDirection="Descending">    


   <TaxonomyFilters>
        <ektron:ContentTaxonomyFilter Operator="Contains"  ID="taxFilter" runat="server" />

    </TaxonomyFilters>

     <ContentFilters>   
       <ektron:ContentFilter Field="Id" Operator="EqualTo" Value=""   />
    </ContentFilters>
</ektron:ContentModelSource>

<ektron:ContentView ID="ContentView1" runat="server"  ModelSourceID="cntModelSourcs"  
    EktronCustomTemplate="Ektron_ContentList_Template" >

</ektron:ContentView>
    </asp:View>
    <div class="ByTaxonomy TSTabPanel">
                    <div style="height: 150px; overflow: auto;">
                        <UC:TaxonomyTree ID="TaxonomyTree1" runat="server" />

                    </div>
                    <hr />

                </div>
    <div class="ByProperty TSTabPanel">
                    <table style="width: auto;">
                        <tr>
                            <td class="label">
                                <%=m_refMsg.GetMessage("lbl taxonomy id:")%>

                            </td>
                            <td>
                                <asp:TextBox ID="taxonomyid" CssClass="folderid" runat="server" Style="width: auto;"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <%=m_refMsg.GetMessage("lbl taxonomy path:")%>
                            </td>
                            <td>
                                <asp:Label ID="taxonomypath" CssClass="taxonomypath" runat="server"></asp:Label>
                              </td> 
                        </tr>                           
                    </table>
                </div>
    <div class="TSEditControls">
                    <asp:Button ID="CancelButton" CssClass="TSCancel" runat="server" Text="Cancel" OnClick="CancelButton_Click" />
                    <asp:Button ID="SaveButton" CssClass="TSSave" runat="server" OnClick="SaveButton_Click" Text="Save" />                       
                </div>
  </div>

</asp:View>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ektron.Cms;
using Ektron.Cms.Widget;
using Ektron.Cms.Common;
using Ektron.Cms.API;
using Ektron.Cms.Organization;
using Ektron.Cms.Framework.Organization;
using System.Text;
using Ektron.Cms.Search.Expressions;
using Ektron.Cms.Search;
using Ektron.Cms.Framework;
public partial class widgets_Content_TaxonomyFilter : System.Web.UI.UserControl,IWidget
{
# region Properties
protected string appPath = "";
private Ektron.Cms.CommonApi _commonAPI = new CommonApi();
private long _taxonomyid;
public string TaxonomySelected = "selected";
public string PropertySelected = "selected";
public string m_strTaxonomyPath = "/";
private string _taxonomypath;

[WidgetDataMember(0)]
public long TaxonomyId { get { return _taxonomyid; } set { _taxonomyid = value; } }

[WidgetDataMember("")]
public string TaxonomyPaths { get { return _taxonomypath; } set { 
_taxonomypath         =       value; } }    private IWidgetHost _host;    
protected ContentAPI m_refContentApi = new ContentAPI();
protected EkMessageHelper m_refMsg;
#endregion

# region Page Load
protected void Page_Load(object sender, EventArgs e)
{
    taxFilter.Value = TaxonomyId.ToString();
    ContentView1.DataBind();
}
#endregion

#region Page Init
protected void Page_Init(object sender, EventArgs e)
{
    m_refMsg = m_refContentApi.EkMsgRef;
    CancelButton.Text = m_refMsg.GetMessage("btn cancel");
    SaveButton.Text = m_refMsg.GetMessage("btn save");
    _host = Ektron.Cms.Widget.WidgetHost.GetHost(this);
    _host.Title = "Templated Control";
    _host.Edit += new EditDelegate(EditEvent);
    _host.Maximize += new MaximizeDelegate(delegate() { Visible = true; });
    _host.Minimize += new MinimizeDelegate(delegate() { Visible = false; });
    _host.Create += new CreateDelegate(delegate() { EditEvent(""); });
    _host.ExpandOptions = Expandable.ExpandOnEdit;
    appPath = _commonAPI.AppPath;
    Load += new EventHandler(delegate(object PreRenderSender, EventArgs Evt) { if 
    (ViewSet.GetActiveView() != Edit) SetTaxonomySummary(); });
    ViewSet.SetActiveView(View);
    }

protected void SetTaxonomySummary()
{
    if (TaxonomyId > 0)
    {
        lblID.Text = Convert.ToString(taxFilter.Value);

    }

}
#endregion

#region EditEvent
void EditEvent(string settings)
{
    try
    {
        string sitepath = _commonAPI.SitePath;
        string webserviceURL = sitepath + "widgets/taxonomysummary/TSHandler.ashx";
        JS.RegisterJSInclude(this, JS.ManagedScript.EktronJS);
        Ektron.Cms.API.JS.RegisterJSInclude(this, 
 Ektron.Cms.API.JS.ManagedScript.EktronJQueryClueTipJS);
        JS.RegisterJSInclude(this, JS.ManagedScript.EktronScrollToJS);
        JS.RegisterJSInclude(this, sitepath + "widgets/taxonomysummary/behavior.js", 
 "TaxonomySummaryWidgetBehaviorJS");

        if (TaxonomyId > 0)
        {
            TaxonomySelected = "";
            JS.RegisterJSBlock(this, "Ektron.PFWidgets.TaxonomySummary.webserviceURL = 
\"" + webserviceURL + "\"; 
 Ektron.PFWidgets.TaxonomySummary.setupAll();
 Ektron.PFWidgets.TaxonomySummary.SetTabs.init()
 ; ", "EktronPFWidgetsTSInit");
        }
        else
        {
            PropertySelected = "";
            JS.RegisterJSBlock(this, "Ektron.PFWidgets.TaxonomySummary.webserviceURL = 
  \"" + webserviceURL + "\"; 
 Ektron.PFWidgets.TaxonomySummary.setupAll(); ", "EktronPFWidgetsTSInit");
        }

        Css.RegisterCss(this, sitepath + "widgets/taxonomysummary/TSStyle.css",  
  "TSWidgetCSS");
        ViewSet.SetActiveView(Edit);
        //set taxonomy path
        Ektron.Cms.API.Content.Taxonomy _apiTaxonomy = new  
        Ektron.Cms.API.Content.Taxonomy();
        Ektron.Cms.TaxonomyRequest taxRequest = new Ektron.Cms.TaxonomyRequest();
        taxRequest.TaxonomyId = TaxonomyId;
        taxRequest.IncludeItems = false;
        taxRequest.TaxonomyLanguage = _apiTaxonomy.ContentLanguage;
        Ektron.Cms.TaxonomyData taxData = _apiTaxonomy.LoadTaxonomy(ref taxRequest);

        if (!(taxData == null || string.IsNullOrEmpty(taxData.Path)))
        {
            taxonomypath.Text = taxData.Path;
            m_strTaxonomyPath = taxData.Path;
        }
        else
        {
            m_strTaxonomyPath = "";
        }
    }
    catch (Exception e)
    {
        ViewSet.SetActiveView(View);
    }
}
#endregion

#region Button Events
protected void CancelButton_Click(object sender, EventArgs e)
{
    ViewSet.SetActiveView(View);

}
protected void SaveButton_Click(object sender, EventArgs e)
{
    int taxID = Convert.ToInt32(taxonomyid.Text);
    TaxonomyId = taxID;
    taxFilter.Value = TaxonomyId.ToString();

    SetTaxonomySummary();
    _host.SaveWidgetDataMembers();
    ViewSet.SetActiveView(View);

}

#endregion

public EventArgs e { get; set; }