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

Group By Column Header

3 Answers 75 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Srujan
Top achievements
Rank 1
Srujan asked on 17 May 2013, 04:23 AM
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 .

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 May 2013, 05:22 AM
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.
0
Srujan
Top achievements
Rank 1
answered on 17 May 2013, 02:08 PM
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
0
Princy
Top achievements
Rank 2
answered on 20 May 2013, 06:02 AM
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.
Tags
General Discussions
Asked by
Srujan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Srujan
Top achievements
Rank 1
Share this question
or