c# - 当数字分开时对数字进行排序
问题描述
我的数据网格中有一个列显示了一些数字。由于这些数字太大,为了更容易阅读,我需要分隔它们的数字。(1985318 -> 1,985,318)我使用以下代码执行此操作:
int value = (int) Convert.ToInt64(GridView.Rows[i].Cells[j].Value);
string seperated = value.ToString("N1", CultureInfo.InvariantCulture);
GridView.Rows[i].Cells[j].Value = seperated.Remove(seperated.Length - 2);
显然,我必须将这些数字的数据类型分配给"LongText"
in MS Access
(因为“1,985,318”不是数字)。但问题是,由于它们被定义为字符串而不是数字,所以当我尝试对它们进行排序时,它们没有正确排序。我想我不能同时将他们的数字分开并正确排序。
您对如何完成有任何建议吗?
解决方案
所以正如 RobertBaron 提到的,我使用字符串格式解决了这个问题。我在 Grid_CellFormatting EventHandler 中使用了以下代码:
private void Grid_CellFormatting(object sender, CellFormattingEventArgs e)
{
GridViewDecimalColumn myCol = Grid.Columns[2] as GridViewDecimalColumn;
myCol.FormatString = "{0:###,###,###,###,###,###,###}";
}
推荐阅读
- python - 如何使用 MergeSort 根据属性对泡菜对象进行排序?
- node.js - 在 AWS Cloudwatch 中查找 lambda 函数错误的日志?
- python - 如何从url路径获取参数?
- git - 复制没有历史记录的 git 存储库
- sql-server - 编写 c# 代码以创建 SSRS 数据驱动订阅
- html - 为什么 flex 中的 `align-items:center` 不能将内部元素作为一个整体垂直居中?
- c# - 谷歌地理代码:将值作为参数传递
- sql - 如何在插入中输入此表中的数据?
- java - 使用 readObject() 反序列化 ArrayList 的 EOFException
- bind9 - Linux Debian 9 与 Bind 9 DNS