在运行时的DataGridView设置DataFormatString? [英] Set DataFormatString on DataGridView at Runtime?

查看:267
本文介绍了在运行时的DataGridView设置DataFormatString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在运行时设置一列或单元格的DataFormatString属性在ASP.NET的DataGridView?

Is it possible to set the DataFormatString property of a column or cell in an ASP.NET DataGridView at runtime?

推荐答案

似乎没有被设置DataFormatString属性的一种方式。我已经结束了数据源绑定表中,然后通过所有的细胞去和手动格式化它们:

There doesn't seem to be a way to set the DataFormatString property. I have ended up binding the datasource to the table and then going through all the cells and formatting them manually:

DataGridView.AutoGenerateColumns = true;
DataGridView.DataSource = dbconnection.getDataReader();
DataGridView.DataBind();

int result;

for (int i = 0; i < DataGridView.Rows.Count; i++)
{
  foreach (TableCell c in DataGridView.Rows[i].Cells)
  {
    if (int.TryParse(c.Text, out result))
    {
      c.Text = String.Format("{0:n0}", result);
    }
  }
}

该方法完全适用于我。不知道它将如何扩大与大型数据集,虽然我的猜测是这将是罚款。

This method works perfectly for me. Not sure how it would scale up with a large dataset although my guess is it would be fine.

这篇关于在运行时的DataGridView设置DataFormatString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆