Voici les étapes pour savoir comment faire:
1) Créer une nouvelle UserControl pour le filtre que vous voulez sous DynamicData \ Filtres. J'ai créé 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>
et le code derrière:
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);
}
}
}
Ensuite, dans votre modèle, juste annoter vos propriétés avec l'attribut FilterUIHint pointant vers le filtre suivant et vous êtes bon aller:
using System; en utilisant System.Collections; en utilisant System.Collections.Generic; en utilisant System.Collections.ObjectModel; en utilisant System.Collections.Specialized;
utilisant System.ComponentModel.DataAnnotations;
espace de noms Test.Model { public partial class actif { #region Propriétés primitives
public virtual int Id
{
get;
set;
}
[FilterUIHint("TextFilter")]
public virtual string Name
{
get;
set;
}
...
beaucoup apprécié! –