This is a migrated thread and some comments may be shown as answers.

Get property bound to column

2 Answers 66 Views
GridView
This is a migrated thread and some comments may be shown as answers.
TMatt
Top achievements
Rank 2
TMatt asked on 25 Jun 2012, 10:59 AM
Hey,

i have a RadGrid bound to a collection of entities i fetch from a webservice:

[DataContract(Name="customer")]
    public class Customer : EntityBase
    {
        private string name;
        [DataMember(Name = "name")]
        [Required]
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                if (this.name != value)
                {
                    this.name = value;
                    OnPropertyChanged("Name");
                }
            }
        }
       ...
   }
}

As i have to do server-side sorting, i need to build a query string from the property of my model the clicked column is bound to. Any idea how i can retrieve the DataMember Name from the column in this event?

private void RadGridView_Sorting(object sender, GridViewSortingEventArgs e)
        {
                        
            string sortDirection;
            string sortColumn; // needs to be "name" for the name column
 
            if (e.NewSortingState == SortingState.Descending)
                sortDirection = " DESC";
            else
            {
                e.NewSortingState = SortingState.Ascending;
                sortDirection = " ASC";
            }
 
            this.vm.Customers.OrderBy = sortColumn + sortDirection;
            this.vm.Customers.IsBusy = true;
            this.vm.Customers.Retrieve();
 
 
        }

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 25 Jun 2012, 11:48 AM
Hello,

In the arguments of the Sorting you could find the column that is sorted on (e.Column). You could get the Name of the column itself.

Does this work for you?
 

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
TMatt
Top achievements
Rank 2
answered on 25 Jun 2012, 01:53 PM
Mah, so easy. Works for me, thanks!
Tags
GridView
Asked by
TMatt
Top achievements
Rank 2
Answers by
Dimitrina
Telerik team
TMatt
Top achievements
Rank 2
Share this question
or