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

Add fields programmatically

5 Answers 148 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
AlefSan
Top achievements
Rank 1
AlefSan asked on 14 May 2014, 08:36 PM
Hi,

When i add a field  programmatically:

Button1_Click:

PivotGridColumnField _row = new PivotGridColumnField();
_row.DataField = "[Account].[Accounts]";
_row.UniqueName = "[Account].[Accounts]";
this.RadPivotGrid1.Fields.Add(_row);

when i interact with him, it raises an error:

Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: Value cannot be null.
Parameter name: fieldInfo

what is the issue ?

sorry my poor english.

5 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 19 May 2014, 07:30 AM
Hello Alef,

Could you please confirm that you add the field into the PageInit event or in PageLoad event as is described into the following documentation article:
http://www.telerik.com/help/aspnet-ajax/pivotgrid-programmatic-creation.html
Additionally it will be helpful if you could post your aspx markup with the related code behind code.
Thus we will be able to gather more details about your scenario and provide you with more to-the-point answer.

Looking forward for your reply.

Regards,
Radoslav
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
AlefSan
Top achievements
Rank 1
answered on 19 May 2014, 01:16 PM
Radoslav,

I wanna add fields on Button Event Click .

I have a Save Button that saves the fields that I added in xml file.
And I have a Load Button that loads the xml file adding  the fields on own places.

ASPX:

        <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
        <telerik:RadAjaxManager runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadPivotGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadPivotGrid1"
                            LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager
 
                ....................
          <td class="tdImage">
                <asp:ImageButton ID="btnOpenCube" runat="server" ImageUrl="~/bsiImages/cube_16x16.png"                                                       OnClick="btnOpenCube_Click" /></td>
         <td class="tdImage">
               <asp:ImageButton ID="btnOpenVis" runat="server" ImageUrl="~/bsiImages/abrir_visao_16x16.png" OnClick="btnOpenVis_Click" /></td>
                ..............
 
                   
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default">
                    </telerik:RadAjaxLoadingPanel>
                    <asp:Panel runat="server" ID="pnlPivot">
                        <telerik:RadPivotGrid ID="RadPivotGrid1" runat="server" AllowFiltering="true" AllowSorting="true"
                            RowTableLayout="Tabular" FieldsPopupSettings-AggregateFieldsMinCount="2" AllowPaging="true"
                            PageSize="20" EnableZoneContextMenu="true" OnPivotGridCellExporting="RadPivotGrid1_PivotGridCellExporting"
                            AggregatesPosition="Rows">
                            <ConfigurationPanelSettings Position="Left" LayoutType="OneByFour" DefaultDeferedLayoutUpdate="false" />
                            <PagerStyle AlwaysVisible="true" />
                        </telerik:RadPivotGrid>
                    </asp:Panel>

Code behind:

protected void btnSaveVis_Click(object sender, ImageClickEventArgs e)
{
    Visao.fields = new List<PivotGridField>();
    foreach (PivotGridField i in this.RadPivotGrid1.Fields)
        Visao.fields.Add(i);
 
    Visao.makeXml();
 
    //Filtros
    //foreach (PivotGridOlapLabelGroupFilter i in this.RadPivotGrid1.Filters)
    //    foreach (MemberDistinctValue x in ((((i.GetDataEngineFilter()) as OlapLabelGroupFilter).Condition) as OlapSetCondition).Items)
    //        x.GetType
 
}
 
protected void btnOpenVis_Click(object sender, ImageClickEventArgs e)
{
    Visao.loadXml();
    foreach (PivotGridField i in Visao.fields)
        this.RadPivotGrid1.Fields.Add(i);
 
    //this.RadPivotGrid1.DataBind();
    //PivotGridRowField _row = new PivotGridRowField();
    //this.RadPivotGrid1.Fields.Add(_row);
    //_row.DataField = "[Account].[Accounts]";
    //_row.UniqueName = "[Account].[Accounts]";
    //this.RadPivotGrid1.DataBind();
}

Thanks.
0
Radoslav
Telerik team
answered on 20 May 2014, 09:35 AM
Hi Alef,

Unfortunately adding filed into the PivotGrid control on button click is not supported scenario. However you can load the fields on PageInit by using following code snippet:
protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
 
        if (Request.Form.Get("ButtonLoadFieldsID") != null)
        {
            // create pivot and load fields
        }
    }


Please give it try and let me know if it helps you. Looking forward for your reply.

Regards,
Radoslav
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
AlefSan
Top achievements
Rank 1
answered on 20 May 2014, 12:50 PM
I understood.

I will try.

Thanks.
0
AlefSan
Top achievements
Rank 1
answered on 02 Jun 2014, 07:07 PM
Hi,

On Init everything occurred ok !

Thanks a lot.
Tags
PivotGrid
Asked by
AlefSan
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
AlefSan
Top achievements
Rank 1
Share this question
or