如何对radgridview进行排序

发布于 2024-11-01 11:03:32 字数 165 浏览 0 评论 0原文

我有一个 radgridview... 我想根据用户单击的按钮按升序/降序对它们进行排序。 我还有一个组合框,其中包含 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 :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

帅气称霸 2024-11-08 11:03:32

这是我的代码,按升序对 ID 进行排序:

在 gridview 中,列是 ID、名称、单价和日期...
希望用户选择要排序的特定列..
我有一个组合框,允许用户选择一列
但我无法获取所选组合框项目的值

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

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
}
}
一张白纸 2024-11-08 11:03:32

我已经解决了这个问题...
我添加了一个组合框,用户可以在其中选择要排序的字段。
这是我的代码:

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

这将按升序排序。要按降序排序,只需将升序替换为降序即可。 :)

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

〆一缕阳光ご 2024-11-08 11:03:32

Telerik 的网站非常清晰,详细介绍了如何对 RadGridView 进行排序: http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/sorting/defaultcs.aspx

你尝试过什么 远的?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文