开发者

Unable to apply dataformat string to Bound columns of datagrid generated dynamically

following is sample code i am trying to make work. i want to apply formatting to datagrid column "price" i want price to be shown in currency format

Dim bColumn As BoundColumn
        bColumn = New BoundColumn
        bColumn.HeaderText = "name"
        bColumn.DataField = "name"
        dgBizDocs.Columns.Add(bColumn)

        bColumn = New BoundColumn
        bColumn.HeaderText = "price"
        bColumn.DataField = "price"
        bColumn.DataFormatString = "{0:C}" ' already tried following "{0:#,##0.00}"
        dgBizDocs.Columns.Add(bColumn)

        Dim dt As New DataTable
        dt.Columns.Add("name")
        dt.Columns.Add("price")

        Dim dr As DataRow
        dr = dt.NewRow
        dr("name") = "ABC"
        dr("price") = 1232100.53
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr("name") = "ABC"
        dr("price") = 123123.32
        dt.Rows.Add(dr)
        dt.AcceptChanges()
        dgBizDocs.DataSource = dt
    开发者_如何学Go    dgBizDocs.DataBind()

what am i doing wrong ?


Specify the price column as decimal in datatable. You will get your formatting (tested).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜