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

How to Handle Exception when adding GridCalculatedColumn?

1 Answer 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pooya
Top achievements
Rank 1
Pooya asked on 12 Sep 2011, 10:17 AM
I have the following method which adds a new GridCalculatedColumn to my Grid.

protected void AddCalculatedColumn(string headerText, string expression, string dataFormatString, params string[] dataFields)
        {
            var calculatedColumn = new GridCalculatedColumn
            {
                DataFields = dataFields,
                HeaderText = headerText,
                Expression = expression,
                DataFormatString = dataFormatString,               
            };


            Product.Columns.Add(calculatedColumn);
        }

I pass 2 decimal values data fields and the expression is "{0}/({0}+{1})" and it throws a divide by 0 exception.

How to handle that when {0} or/and {1} is null then the total value which is displayed to be 0 instead of throwing this exception?

What can be set as an expression?

Thanks,

1 Answer, 1 is accepted

Sort by
0
Pooya
Top achievements
Rank 1
answered on 12 Sep 2011, 11:24 AM
Fixed:

iif({0}=null or {0}=0.00 or {1}=null or {1}=0.00,0.00,{0}*100/({0}+{1}))

When the problem is explained well, the solution often emerges automatically :)
Tags
Grid
Asked by
Pooya
Top achievements
Rank 1
Answers by
Pooya
Top achievements
Rank 1
Share this question
or