简体   繁体   English

如何在GridView中实现行排序?

[英]How to implement row sorting in GridView?

I'm developing an application in asp.net, how can I perform the following on GridView control? 我正在asp.net中开发应用程序,如何在GridView控件上执行以下操作?

GridView control ave a "sequence" column with DropDownList (choice of 1,2,3,4...) to allow rows sorting, user can select numbers from DropDownList as the row sequence. GridView控件具有一个带有DropDownList的“序列”列(选择1,2,3,4 ...)以允许对行进行排序,用户可以从DropDownList中选择数字作为行序列。

The sequence should not repeating, mean selected number should not appear twice. 该序列不应重复,表示所选编号不应出现两次。

Can it be done? 能做到吗 please advise. 请指教。

Thank you in advanced. 在此先感谢您。

If I understand, you want to be able to sort your rows using a DropDownList that is a cell in each row. 据我了解,您希望能够使用DropDownList来对行进行排序,而DropDownList是每行中的一个单元格。 You want this SortOrder value on each row to have a unique value (so no row has the same SortOrder). 您希望每行上的此SortOrder值具有唯一值(因此,没有行具有相同的SortOrder)。 You can accomplish this with a little programming... you could implement something to validate that each choice is a unique one. 您可以通过一些编程来实现这一点...您可以实现一些方法来验证每个选择都是唯一的。 Or, when you select say "3" on a row, then remove "3" as a selection from the DropDownList of the other boxes. 或者,当您连续选择说“ 3”时,请从其他框的DropDownList中删除“ 3”作为选择。

For sorting, a DataView helps, which you can turn back into a table. 对于排序,DataView可以帮助您将其转换为表格。

DataView dv = yourGridView.DefaultView;
dv.Sort = "SortOrder desc";
DataTable newSortedDt = dv.ToTable();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM