开发者

how to sort radgridview

开发者 https://www.devze.com 2023-02-24 11:28 出处:网络
i have a radgridview... i want to sort them in ascending/descending depending on the button that the user clicks.

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 开发者_StackOverflow中文版with this one?

thanks :)


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
}
}


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. :)


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消