2009-12-03 5 views
0

통화로 gridview 열 바닥 글 값의 서식을 지정하는 방법이 있습니까? } BoundField의 DataFormatString을 {0 : c}로 설정했는데 이것은 바닥 글에 영향을 미치지 않는 것 같습니다. RowDataBound 이벤트에서이 작업을 수행해야합니까?Gridview 바닥 글 데이터 형식 문자열

답변

0

나는이 비슷한 방법으로 그 일을 결국 ...

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"); 
    } 
} 
0

바닥 글에 HtmlEncode = "False"를 설정 했습니까?

편집 : 잠시 동안 알려진 문제입니다.

0

는 그것은 kludge입니다. (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; 
} 
0

이 나를 위해 작동합니다

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); 
}