を次の属性我々が使用する必要のあるエンティティのメタデータクラス、すなわち、DefaultSortOrderColumn
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class DefaultSortColumnAttribute : Attribute
{
public DefaultSortColumnAttribute(string sortColumn, bool sortDescending)
{
this.SortColumn = sortColumn;
this.SortDescending = sortDescending;
}
public string SortColumn { get; private set; }
public bool SortDescending { get; private set; }
}
次に部分エンティティクラスでは、この属性を使用して -
私は、ソート列を追加するための新しい属性クラスを追加しましたソート列
私たちはその後、定義された任意のsortcolumnsがあるかどうかを決定し、Page_Loadの中にそれをソートするPageTemplates \ List.aspxでこの属性を使用することができます
[DefaultSortColumn("YourSortColumn", false)]
public partial class YourDBEntity
{
}
。
MetaTable table = GridDataSource.GetTable();
if (!IsPostBack && table.Attributes.OfType<DefaultSortColumnAttribute>().Count() > 0)
{
string sortColumn = table.Attributes.OfType<DefaultSortColumnAttribute>().FirstOrDefault().SortColumn;
bool sortDescending = table.Attributes.OfType<DefaultSortColumnAttribute>().FirstOrDefault().SortDescending;
GridView1.Sort(sortColumn, sortDescending ? SortDirection.Descending : SortDirection.Ascending);
}
この属性をさらに拡張し、クラスではなくプロパティに設定することができます。そうすれば、複数の列を並べ替えることができます。
返信いただきありがとうございます。ハッピーコーディング。