What is the easiest way to sort the Grid (not the dropdown box) in the List.aspx based on a
foreign key column in the grid?
This is the Entity
I am using the DisplayColumn attribute to sort the dropdown boxes but it does not work for the grid.
[MetadataType(typeof(UserMetaData))]
[DisplayColumn("FirstName", "FirstName", false)]
public partial class User
{
public override string ToString()
{
return FirstName + " " + LastName;
}
internal class UserMetaData
{
[DisplayName("Name")]
public object FirstName{ get; set; }
[DisplayName("Last Name")]
public object LastName{ get; set; }
}
}
Here I have the foreign key User
public partial class ITInventory
{
public class ITInventoryMetaData
{
public object Active;
[DisplayName("Mobile No")]
public object MobileNo { get; set; }
[DisplayName("Users")]
public object User { get; set; }
}
}
Member
18 Points
156 Posts
Sort DataGrid based on Foreign key
Feb 18, 2013 07:48 AM|pallone|LINK
Hi,
What is the easiest way to sort the Grid (not the dropdown box) in the List.aspx based on a foreign key column in the grid?
This is the Entity
Cheers,
CP
Member
18 Points
156 Posts
Re: Sort DataGrid based on Foreign key
Feb 18, 2013 12:16 PM|pallone|LINK
I saw this article but it does not seem to work for me since I want to sort the grid using a foreign entity
http://csharpbits.notaclue.net/2011/01/setting-initial-sort-order-dynamic-data.html
table = GridDataSource.GetTable();
// set default sort if (!IsPostBack && table.SortColumn != null) GridView1.Sort(table.SortColumn.Name, table.SortDescending ? SortDirection.Descending : SortDirection.Ascending);