Respuesta

9

Estos son los pasos para saber cómo hacer esto:

1) Crear un nuevo control de usuario para el filtro que desee en DynamicData \ filtros. He creado un TextFilter.ascx:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TextFilter.ascx.cs" Inherits="Test.Prototype.Web.DynamicData.DynamicData.Filters.TextFilter" %> 
<asp:TextBox runat="server" ID="TextBox1" AutoPostBack="true" OnTextChanged="TextBox1_OnTextChanged" CssClass="DDFilter"> 
</asp:TextBox> 

y el código subyacente:

using System; 
using System.Collections; 
using System.Collections.Generic; 
using System.Collections.Specialized; 

using System.ComponentModel.DataAnnotations; 
using System.Linq; 

using System.Linq.Expressions; 
using System.Web.DynamicData; 
using System.Web.UI; 
using System.Web.UI.WebControls; 


namespace Test.Prototype.Web.DynamicData.DynamicData.Filters 
{ 
    public partial class TextFilter : System.Web.DynamicData.QueryableFilterUserControl 
    { 

     private const string NullValueString = "[null]"; 

     protected void Page_Load(object sender, EventArgs e) 
     { 

     } 

     public override Control FilterControl 
     { 
      get 
      { 
       return TextBox1; 
      } 
     } 


     protected void TextBox1_OnTextChanged(object sender, EventArgs e) 
     { 
      OnFilterChanged(); 
     } 

     public override IQueryable GetQueryable(IQueryable source) 
     { 
      string selectedValue = TextBox1.Text; 
      if (String.IsNullOrEmpty(selectedValue)) 
      { 
       return source; 
      } 

      object value = selectedValue; 
      if (selectedValue == NullValueString) 
      { 
       value = null; 
      } 
      if (DefaultValues != null) 
      { 
       DefaultValues[Column.Name] = value; 
      } 

      return ApplyEqualityFilter(source, Column.Name, value); 

     } 

    } 
} 

Luego, en su modelo, simplemente anotar sus propiedades con el atributo FilterUIHint que apunta al siguiente filtro y ya está bueno para ir:

usando Sistema; usando System.Collections; usando System.Collections.Generic; usando System.Collections.ObjectModel; usando System.Collections.Specialized;

usando System.ComponentModel.DataAnnotations;

Propiedades

espacio de nombres Test.Model { Activos clase parcial pública { #region primitivos

public virtual int Id 
    { 
     get; 
     set; 
    } 

    [FilterUIHint("TextFilter")] 
    public virtual string Name 
    { 
     get; 
     set; 
    } 

...

+0

muy apreciada! –

Cuestiones relacionadas