We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to change the cell value in OLAP Grid?

Platform: ASP.NET Web Forms (Classic) |
Control: OlapGrid |
Published Date: September 16, 2015 |
Last Revised Date: July 2, 2019

This KB illustrates that how to change the cell value in OLAP Grid.

Solution

You can change the cell value in the OlapGrid in two ways.

  1. By using the QueryCellInfo event of the OlapGrid control.
  2. By editing the DOM element.

 

Using the QueryCellInfo event

The QueryCellInfo event gives two parameters, CellDescriptor and Cell. The CellDescriptor parameter helps you to select the position of the cell and the Cell parameter helps you to change the cell value. By using the Text property in the Cell parameter, you can change the cell content.

Note:

This event is invoked every time a new cell is created.

 

The following code example illustrates how to set or change the cell value of the OlapGrid by using the QueryCellInfo event.

 

C#

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
    }
    this.OlapClient1.OlapGrid.QueryCellInfo+=OlapGrid_QueryCellInfo;
}
private void OlapGrid_QueryCellInfo(object sender, CellInfoEventArgs e)
{
    if (e.CellDescriptor.PivotRowIndex < 2 && e.CellDescriptor.CellIndex > 2)
        e.Cell.Text = "Your value here";
}

 

VB

Protected Sub Page_Load(sender As Object, e As EventArgs)
    If Not IsPostBack Then
    End If
    AddHandler Me.OlapClient1.OlapGrid.QueryCellInfo, AddressOf OlapGrid_QueryCellInfo
End Sub
Private Sub OlapGrid_QueryCellInfo(sender As Object, e As CellInfoEventArgs)
    If e.CellDescriptor.PivotRowIndex < 2 AndAlso e.CellDescriptor.CellIndex > 2 Then
        e.Cell.Text = "Your value here"
    End If
End Sub

 

Editing the DOM element

Another method of changing the cell value is to edit the DOM element under the PreRender event. By using the FindControl() method, the OlapGrid can be tracked in the table pattern. The particular cell position in the table can be detected by iterating the rows and columns of the table. The path of the header cells in the table is different from other cell types because of the expanders in the header cells.

The following code example illustrates how to set or change the cell value of the OlapGrid by using the QueryCellInfo event.

 

C#

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
    }
    this.OlapClient1.OlapGrid.PreRender += OlapGrid_PreRender;
}
private void OlapGrid_PreRender(object sender, EventArgs e)
{
     //The Header cells with expander and collapse symbol.
(((Page.FindControl("OlapClient1").FindControl(this.OlapClient1.OlapGrid.ID).Controls[1] as Table).Rows[0].Cells[3].Controls[1]) as Literal).Text = "Some Text";
    //The Header cells without expander and collapse symbol, applicable for value cells also.
(((Page.FindControl("OlapClient1").FindControl(this.OlapClient1.OlapGrid.ID).Controls[1] as Table).Rows[0].Cells[3].Text)  = "Some Text";
}

 

VB

Protected Sub Page_Load(sender As Object, e As EventArgs)
    If Not IsPostBack Then
    End If
    AddHandler Me.OlapClient1.OlapGrid.PreRender, AddressOf OlapGrid_PreRender
End Sub
Private Sub OlapGrid_PreRender(sender As Object, e As EventArgs)
    'The Header cells with expander and collapse symbol.
TryCast(TryCast(Page.FindControl("OlapClient1").FindControl(Me.OlapClient1.OlapGrid.ID).Controls(1), Table).Rows(0).Cells(3).Controls(1), Literal).Text = "Some Text"
    'The Header cells without expander and collapse symbol, applicable for value cells also.
TryCast(TryCast(Page.FindControl("OlapClient1").FindControl(Me.OlapClient1.OlapGrid.ID).Controls(1), Table).Rows(0).Cells(3).Text) = "Some Text"
End Sub

 

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon