代码之家  ›  专栏  ›  技术社区  ›  Germ

Gridview页脚数据格式字符串

  •  0
  • Germ  · 技术社区  · 16 年前

    是否有方法将gridview列页脚值格式化为货币。我将BoundField的DataFormatString设置为{0:c},但这似乎不会影响页脚。我必须在RowDataBound事件中执行此操作吗?

    4 回复  |  直到 16 年前
        1
  •  0
  •   Ta01    16 年前

    编辑:这是一个已知的问题已经有一段时间了。

        2
  •  0
  •   Germ    16 年前

    我最终以类似的方式做了这件事。。。

    protected void gridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        double dVal = 0.0;
    
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            dVal += Convert.ToDouble(e.Row.Cells[1].Text);
        }
    
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            e.Row.Cells[1].Text = dVal.ToString("c");
        }
    }
    
        3
  •  0
  •   Nathan    14 年前

    这是一个难题(sp?)

    但有时在面对已知的问题时,你必须左右为难(sp?)

    private static string FormatByGridView(object value, string DataFormatString)
    {
        GridView grid = new GridView();
        DataTable table = new DataTable();
        table.Columns.Add("value", value.GetType());
        var row = table.NewRow();
        row["value"] = value;
        table.Rows.Add(row);
        grid.Columns.Add(new BoundField() { DataField = "value", DataFormatString = DataFormatString });
        grid.DataSource = table;
        grid.DataBind();
        return grid.Rows[0].Cells[0].Text;
    }
    
        4
  •  0
  •   Stephen Rauch Afsar Ali    8 年前

    if (e.Row.RowType == DataControlRowType.Footer)
    {
       e.Row.Cells[2].Text = string.Format("{0:#,###,###.00}", total2013);
       e.Row.Cells[3].Text = string.Format("{0:#,###,###.00}", total2014);
    }