This is a migrated thread and some comments may be shown as answers.

radgrid DataFormatString String Value To Decimal

2 Answers 1444 Views
Grid
This is a migrated thread and some comments may be shown as answers.
nitesh monga
Top achievements
Rank 1
nitesh monga asked on 27 Aug 2009, 08:36 AM

Hi There, I need a litle help with GridBoundColumn DataFormateString Property. I have boundcolumn which shows the values like:

0
1.0
1.88
3.0

The values should appear like:

0.00
1.00
1.88
3.00

 

Is there any easy way that can be used with GridBoundColumns to get the above results. any example will be a gr8 help :).

Thanks & Regards
Nitesh Monga

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Aug 2009, 09:42 AM
Hi Nitesh,

Try setting the DataFormatString of the GridBoundColumn as shown below.

ASPX:
 <telerik:GridBoundColumn  DataType="System.Int32"  DataField="Sum" DataFormatString="{0:F2}"  HeaderText="Sum" SortExpression="Sum" UniqueName="Sum"
                        </telerik:GridBoundColumn> 


Thanks
Shinu



0
nitesh monga
Top achievements
Rank 1
answered on 27 Aug 2009, 10:20 AM
Dear Shinu thanks allot for your response i tried that but it didn't worked for me, i found a other way around for this problem. below is the approach i used to fix my problem.

Private Sub RadGrid1_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound  
        If TypeOf e.Item Is GridDataItem Then 
 
Dim dblVal As String 
            dblVal = TryCast(dataItem("sumHrs"), TableCell).Text  
            TryCast(dataItem("sumHrs"), TableCell).Text = fixZero(dblVal)  
            End If 
    End Sub 
    Function fixZero(ByVal val As StringAs String 
        Dim dVal As Decimal 
        val = val.Replace("&nbsp;""")  
        If val <> "" Then 
            dVal = val  
        Else 
            dVal = 0  
        End If 
        Dim dc As String 
        dc = dVal.Round(dVal, 2).ToString  
        If dc.IndexOf(".") <= 0 Then 
            dc = dc + ".00" 
        Else 
            Dim index As Integer 
            Dim dec As String 
            index = dc.LastIndexOf(".")  
            dec = dc.Substring(index)  
            If dec.Length = 2 Then 
                dc = dc + "0" 
            End If 
        End If 
        val = dc  
        Return val  
    End Function 
Tags
Grid
Asked by
nitesh monga
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
nitesh monga
Top achievements
Rank 1
Share this question
or