Add fields programmatically

6 posts, 0 answers
  1. AlefSan
    AlefSan avatar
    4 posts
    Member since:
    May 2014

    Posted 14 May 2014 Link to this post

    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.
  2. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 19 May 2014 Link to this post

    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. AlefSan
    AlefSan avatar
    4 posts
    Member since:
    May 2014

    Posted 19 May 2014 in reply to Radoslav Link to this post

    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.
  5. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 20 May 2014 Link to this post

    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.

     
  6. AlefSan
    AlefSan avatar
    4 posts
    Member since:
    May 2014

    Posted 20 May 2014 in reply to Radoslav Link to this post

    I understood.

    I will try.

    Thanks.
  7. AlefSan
    AlefSan avatar
    4 posts
    Member since:
    May 2014

    Posted 02 Jun 2014 in reply to Radoslav Link to this post

    Hi,

    On Init everything occurred ok !

    Thanks a lot.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017