loraine96
loraine96

Reputation: 21

how to sort radgridview

i have a radgridview... i want to sort them in ascending/descending depending on the button that the user clicks. i also have a combobox that contains the column names in the radgridview which the user chooses to sort the data based on the column names...

unfortunately, i don't know how to do it...

can you help m with this one?

thanks :)

Upvotes: 2

Views: 7041

Answers (3)

711721
711721

Reputation: 41

i have solved this problem... i added a combobox where users can select the field to be sorted. here's my code:

private void SortAsc_Click(object sender, System.Windows.RoutedEventArgs e)
{
    RadComboBoxItem comboItem = combobox1.SelectedItem as RadComboBoxItem;
    string selectedItem = comboItem.Content.ToString();
    RadGridView1.SortDescriptors.Add(new SortDescriptor()
    {
        Member=selectedItem,
        SortDirection = System.ComponentModel.ListSortDirection.Ascending
    });
}

this will sort in ascending order. to sort in descending order, just replace Ascending with Descending. :)

Upvotes: 1

loraine96
loraine96

Reputation: 21

here's my code that sorts the ID in ascending order:

in the gridview, the columns are ID, Name, UnitPrice, and date... want the user to choose a specific column that which will be sorted.. i have a combobox that allows the user to choose a column but i can't get the value of the selected combobox item

private void SortAsc_Click(object sender, System.Windows.RoutedEventArgs e)
{
RadGridView1.SortDescriptors.Add(new SortDescriptor()
{
Member ="ID",
SortDirection = System.ComponentModel.ListSortDirection.Ascending
}
}

Upvotes: 1

NakedBrunch
NakedBrunch

Reputation: 49413

Telerik's site is pretty clear and goes through a lot of detail on how to sort a RadGridView: http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/sorting/defaultcs.aspx

What you have tried so far?

Upvotes: 0

Related Questions