English 中文(简体)
在伙伴关系中增加一个分组模板: 在任何标题模板之后显示的复式
原标题:Add a grouping template to a ASP:Repeater that displays after any header template

I have sub classed a asp repeater similar to A Grouping Repeater All works fine apart from if I also have a <HeaderTemplate> </HeaderTemplate> The grouping template is rendered before the header template.

我真的希望要么能够选择模板的顺序,要么仅仅有<代码><GroupTemplate>。 排在头盔后。

问题回答

你们是否尝试了皮条客? 如果我们不能看到你重新运行的法典,我们就能够评估你。 请举例说明。

The simplier one from the comments:

using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;


    /// <summary> 
    /// This wraps the Web Repeater class and adds grouping capabilities.
    /// </summary> 
    public class GroupingRepeater : Repeater
    {

        private string _lastGroup;
        private string _groupColumn;
        private ITemplate _groupTemplate;

        /// <summary> 
        /// Gets or sets the column to group by.
        /// </summary> 
        [Browsable(true), Category("Behaviour")]
        public string GroupColumn
        {
            get { return _groupColumn; }
            set { _groupColumn = value; }
        }

        /// <summary> 
        /// Gets or sets the template used for Grouping.
        /// </summary> 
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [Browsable(false)]
        [TemplateContainer(typeof(RepeaterItem))]
        [DefaultValue("")]
        public virtual ITemplate GroupTemplate
        {
            get { return _groupTemplate; }
            set { _groupTemplate = value; }
        }

        /// <summary> 
        /// Default constructor.
        /// </summary> 
        public GroupingRepeater()
        {
            _lastGroup = null;
        }

        /// <summary> 
        /// Called when an item is created.
        /// </summary> 
        /// <param name="e"></param> 
        protected override void OnItemCreated(RepeaterItemEventArgs e)
        {
            base.OnItemCreated(e);

            if (!string.IsNullOrEmpty(GroupColumn))
            {
                string currentGroup = e.Item.DataItem.GetType().GetProperty(GroupColumn).GetValue(e.Item.DataItem, null).ToString();
                if (_lastGroup == null || _lastGroup != currentGroup)
                {
                    RepeaterItem item = new RepeaterItem(0, ListItemType.Item);

                    GroupTemplate.InstantiateIn(item);
                    item.DataItem = e.Item.DataItem;
                    this.Controls.Add(item);
                    item.DataBind();

                    _lastGroup = currentGroup;
                }
            }
        }

    }




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签