开发者

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

开发者 https://www.devze.com 2023-02-04 21:21 出处:网络
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

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

精彩评论

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