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

GridCalculatedColumn not populating if One of the column is Null.

3 Answers 165 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 05 Oct 2010, 09:47 PM

Folks,

Environment Radgrid for Asp.net Ajax 2010_2_826, VS 2008 SP1.

In my Radgrid I have 3 columns. Salary,  ExperienceDifferential and GrossSalary (CalculatedColumn).

I would like to have that CalculatedColumn be populated with the sum of columns Salary and ExperienceDifferential whether these 2 columns are null or not. What I noticed if ExperienceDifferential is null, the CalculatedColumn does not populate, but if ExperienceDifferential is not null CalculatedColumn does populate. Question is in order for CalculatedColumn to work, does other related columns must be not null?

Below is my column declarations and attached is the result set.

Thanks

GC_0620
___________________

<telerik:GridTemplateColumn DataField="Salary" DataType="System.Decimal" HeaderText="Salary"
                  SortExpression="Salary" UniqueName="Salary">
                  <ItemTemplate>
                      <asp:Label ID="SalaryLabel" runat="server" Text='<%# Bind( "Salary","{0:N2}") %>'></asp:Label>
                  </ItemTemplate>
              </telerik:GridTemplateColumn>

              <telerik:GridBoundColumn DataField="ExperienceDifferential" DataType="System.Decimal"
                  DataFormatString="{0:N2}" HeaderText="Experience Differential" SortExpression="ExperienceDifferential"
                  UniqueName="ExperienceDifferential">
              </telerik:GridBoundColumn>

              <telerik:GridCalculatedColumn DataType="System.Decimal" DataFormatString="{0:N2}"
                  DataFields="Salary,ExperienceDifferential" Expression="{0}+ {1}" HeaderText="Gross Salary"
                  UniqueName="GrossSalary" Aggregate="Sum">
              </telerik:GridCalculatedColumn>


3 Answers, 1 is accepted

Sort by
0
Matthew
Top achievements
Rank 1
answered on 05 Oct 2010, 11:06 PM
By nature, you cannot perform math operations on a NULL value.

NULL means that a value is withheld. It is not equivalent to zero. 
This is actually in the SQL standard as well, such that 
1+NULL = NULL

You will need to implement some logic on your own to convert NULL values to zero
0
gc_0620
Top achievements
Rank 1
answered on 06 Oct 2010, 02:02 AM
Matthew,

The issue here is column ExperienceDifferential is a gridboundcolumn. How do I convert a null value (if any) to zero of a gridboundcolumn, add it with another templatecolumn and  populate a calculatedcolumn? In ItemDatabound event?

Ideally I would like to see when Radgrid first opens as well as after insert/update, the calculatedcolumn ( GrossSalary) will be populated with the values of Salary+ExperienceDifferential.

Example in Radgrid Columns  and desired result:

Salary                ExperienceDifferential       GrossSalary
10.00                        2.00                                        12.00
  5.00                                                                         5.00


Basically I want to output the Calculatedcolumn in PDF Export. If that Calculatedcolumn can be populated in PDF export event, will be fine but ideally I would like to see it in Radgrid.  Thanks


0
gc_0620
Top achievements
Rank 1
answered on 06 Oct 2010, 04:04 PM

Solved. All I need to assign a default value to 0 to that column.

<UpdateParameters>
          '''
           <asp:Parameter Name="ExperienceDifferential" Type="Decimal" DefaultValue = "0" />
          '' 
</UpdateParameters
Tags
Grid
Asked by
gc_0620
Top achievements
Rank 1
Answers by
Matthew
Top achievements
Rank 1
gc_0620
Top achievements
Rank 1
Share this question
or