Category / Section
How to display measure value in different formats?
1 min read
You can display the single measure value in different formats using RowBound event.
C#
protected void Page_Init(object sender, EventArgs e) { this.OlapGrid1.RowBound += new eventHandler<RowBoundEventArgs>(OlapGrid1_RowBound); } void OlapGrid1_RowBound(object sender, RowBoundEventArgs e) { //To Displayt the particular products Amount Measure with different products. double amount = 0, result; if (double.TryParse((e.GridRow.Cells[0] as TableCell).Text, out result)) amount = result; if (e.FrozenRow != null) { PivotCellDescriptor cellDesc = (e.GridRow.Cells[0] as PivotGridCell).CellDescriptor; for (int i = 0; i < cellDesc.CellData.Rows.Count; i++) { //Display the Amount values with format {0:0.0000} for Bike Product if (cellDesc.CellData.RowInfo[i].UniqueName == "Product" && cellDesc.CellData.RowInfo[i].Name == "Bike" && cellDesc.CellData.Measure == "Amount") { (e.GridRow.Cells[0] as TableCell).Text = String.Format("{0:0.0000}", amount); } //Display the Amount values with format {0:0.0000} for Car Product if (cellDesc.CellData.RowInfo[i].UniqueName == "Product" && cellDesc.CellData.RowInfo[i].Name == "Car" && cellDesc.CellData.Measure == "Amount") { (e.GridRow.Cells[0] as TableCell).Text = String.Format("{0:0.0}", amount); } } } }
VB
Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) AddHandler OlapGrid1.RowBound, AddressOf OlapGrid1_RowBound End Sub Private Sub OlapGrid1_RowBound(ByVal sender As Object, ByVal e As RowBoundEventArgs) 'To Displayt the particular products Amount Measure with different products. Dim amount As Double = 0, result As Double If Double.TryParse((TryCast(e.GridRow.Cells(0), TableCell)).Text, result) Then amount = result End If If e.FrozenRow IsNot Nothing Then Dim cellDesc As PivotCellDescriptor = (TryCast(e.GridRow.Cells(0), PivotGridCell)).CellDescriptor For i As Integer = 0 To cellDesc.CellData.Rows.Count - 1 'Display the Amount values with format {0:0.0000} for Bike Product If cellDesc.CellData.RowInfo(i).UniqueName = "Product" AndAlso cellDesc.CellData.RowInfo(i).Name = "Bike" AndAlso cellDesc.CellData.Measure = "Amount" Then (TryCast(e.GridRow.Cells(0), TableCell)).Text = String.Format("{0:0.0000}", amount) End If 'Display the Amount values with format {0:0.0000} for Car Product If cellDesc.CellData.RowInfo(i).UniqueName = "Product" AndAlso cellDesc.CellData.RowInfo(i).Name = "Car" AndAlso cellDesc.CellData.Measure = "Amount" Then (TryCast(e.GridRow.Cells(0), TableCell)).Text = String.Format("{0:0.0}", amount) End If Next i End If End Sub