Group By Column Header

4 posts, 0 answers
  1. Srujan
    Srujan avatar
    18 posts
    Member since:
    Oct 2010

    Posted 16 May 2013 Link to this post

    Hi Team ,

    I am trying to set up group by experssion from code behind , When I set Count as Aggregate fucntion on bound column I am getting below error

    Input string was not in a correct format.Couldn't store <Value> in Column.  Expected type is Decimal.

    Below is the Code I am using , can you please suggest how to proceed further 

     GridGroupByExpression expression = new GridGroupByExpression();
                    GridGroupByField gridGroupByField = new GridGroupByField();
                    gridGroupByField.FieldName = "<BoundColumnName>";
                    gridGroupByField.HeaderText = "<HeaderText> ";
                    gridGroupByField.HeaderValueSeparator = "";
                    gridGroupByField.FormatString = "<strong>{0:0.00}</strong>";
                    gridGroupByField.Aggregate = GridAggregateFunction.Count;
                    expression.SelectFields.Add(gridGroupByField);

    Thanks in advance .
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 17 May 2013 Link to this post

    Hi,

    I have tried the following code to replicate your scenario and it worked as expected on my end.
    C#:
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
       {
           if (e.Item is GridDataItem)
           {
               GridDataItem dataItem = e.Item as GridDataItem;
               GridGroupByExpression exp = new GridGroupByExpression();
               GridGroupByField expfield = new GridGroupByField();
               expfield = new GridGroupByField();
               expfield.FieldName = "OrderID";
               expfield.HeaderText = "Order count ";
               expfield.FormatString = "<strong>{0:0.00}</strong>";
               expfield.Aggregate = GridAggregateFunction.Count;
               exp.SelectFields.Add(expfield);
               expfield = new GridGroupByField();
               expfield.FieldName = "Discount";
               exp.GroupByFields.Add(expfield);
               this.RadGrid1.MasterTableView.GroupByExpressions.Add(exp);
               int fieldValue = int.Parse(dataItem["OrderID"].Text);
               total += fieldValue;
           }
           if (e.Item is GridGroupFooterItem)
           {
               GridGroupFooterItem itm = e.Item as GridGroupFooterItem;
               itm["OrderID"].Text = "Total :" + total.ToString();
               total = 0;
           }
       }

    Hope this will help.

    Thanks,
    Princy.
  3. Srujan
    Srujan avatar
    18 posts
    Member since:
    Oct 2010

    Posted 17 May 2013 Link to this post

    Hi Princy ,

    I am trying to display count which would not require type cast (i.e. number of items in the group) .also I am trying to display this value as group header , can you please suggest how to proceed further .

    Thanks
    Srujan.N
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 20 May 2013 Link to this post

    Hi,

    I have tried the following code to show count in group header with "Order Count " as my header text and it worked as expected on my end.

    C#:
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem dataItem = e.Item as GridDataItem;
                GridGroupByExpression exp = new GridGroupByExpression();
                GridGroupByField expfield = new GridGroupByField();
                expfield = new GridGroupByField();
                expfield.FieldName = "OrderID";
                expfield.HeaderText = "Order count ";
                expfield.FormatString = "<strong>{0:0.00}</strong>";
                expfield.Aggregate = GridAggregateFunction.Count;
                exp.SelectFields.Add(expfield);
                expfield = new GridGroupByField();
                expfield.FieldName = "Discount";
                exp.GroupByFields.Add(expfield);
                this.RadGrid1.MasterTableView.GroupByExpressions.Add(exp);
           }
        }

    Hope this will help.
    Thanks,
    Princy.
Back to Top