【问题标题】:.NET datagrid sort incorrectly.NET 数据网格排序不正确
【发布时间】:2012-07-31 23:17:14
【问题描述】:

我在下面有一个 .NET DataGrid,它不对列进行排序。比如排序是这样的

10 100 21 即使 DataFormatString="{0:N0} 已设置,排序仍然无法正常工作。请帮助。

<asp:DataGrid ID="StatusGrid" CssClass="StatusGrid" runat="server" AutoGenerateColumns="false"
    UseAccessibleHeader="true" OnItemDataBound="StatusGrid_ItemDataBound" OnItemCommand="StatusGrid_ItemCommand">
    <Columns>

            ItemStyle-HorizontalAlign="Left" />
        <asp:BoundColumn DataField="Rating" HeaderText="Performance Rating" ItemStyle-Width="110px"
            ItemStyle-HorizontalAlign="Left" DataFormatString="{0:N0}"/>

    </Columns>

【问题讨论】:

  • 你的数据类型是字符串还是整数?

标签: asp.net .net sorting datagrid


【解决方案1】:

这可能是列的数据类型有问题。它的排序就像它是一个字符串而不是一个数字。您的 DataFormatString 想法是正确的,但您需要将数据作为 int 传递到该列,或者实现此处描述的一些自定义排序:

http://msdn.microsoft.com/en-us/library/aa984282(v=vs.71).aspx

【讨论】:

  • 在 DB 中是整数。当绑定到数据网格时,我看不到明显的字符串转换。
猜你喜欢
  • 2013-11-08
  • 1970-01-01
  • 1970-01-01
  • 2015-05-04
  • 2011-05-18
  • 2019-12-27
  • 2010-12-12
  • 2022-01-13
  • 1970-01-01
相关资源
最近更新 更多