Dynamic Data ---MetaData 之 Filter

 1、FKFilter.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="FKFilter.ascx.cs" Inherits="BtmsWebApp.DynamicData.Filters.FKFilter" %>
<asp:DropDownList ID="DropDownList1" runat="server" EnableViewState="true"
    CssClass="droplist">
    <asp:ListItem Text="全部" Value="" />
</asp:DropDownList>

2、FKFilter.ascx.cs

public partial class FKFilter : FilterUserControlBase, ISelectionChangedAware
    {

        public event EventHandler SelectionChanged
        {
            add
            {
                DropDownList1.SelectedIndexChanged += value;
            }
            remove
            {
                DropDownList1.SelectedIndexChanged -= value;
            }
        }

        public override string SelectedValue
        {
            get
            {
                return DropDownList1.SelectedValue;
            }
        }

        protected void Page_Init(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                PopulateListControl(DropDownList1);

                // Set the initial value if there is one
                if (!String.IsNullOrEmpty(InitialValue))
                    DropDownList1.SelectedValue = InitialValue;
            }
        }
    }

3、 public virtual FilterUserControlBase GetFilterControl(MetaColumn column)
            {
                if (column == null)
                {
                    throw new ArgumentNullException("column");
                }

                string filterTemplatePath = null;

                string filterControlName = "FKFilter";

                FilterAttribute filterAttribute = column.Attributes.OfType<FilterAttribute>().FirstOrDefault();
                if (filterAttribute != null)
                {
                    if (!filterAttribute.Enabled)
                    {
                        throw new InvalidOperationException(String.Format("The column '{0}' has a disabled filter", column.Name));
                    }

                    if (!String.IsNullOrEmpty(filterAttribute.FilterControl))
                    {
                        filterControlName = filterAttribute.FilterControl;
                    }
                }

                filterTemplatePath = VirtualPathUtility.Combine(FilterFolderVirtualPath, filterControlName + ".ascx");

                var filter = (FilterUserControlBase)BuildManager.CreateInstanceFromVirtualPath(
                    filterTemplatePath, typeof(FilterUserControlBase));

                return filter;
            }
        }

4、调用

 [Filter(FilterControl = "FKFilter ")]

 public object Classes { get; set; }

阅读更多
想对作者说点什么? 我来说一句
相关热词

没有更多推荐了,返回首页

关闭
关闭
关闭