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

Calculated Column

2 Answers 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alan
Top achievements
Rank 1
Alan asked on 22 Feb 2011, 04:41 PM
Hi,

I am trying to create a calculated column, which I have succeeded in doing, but filtering and grouping is triggering a javascript exception.

This is my code:

<telerik:RadGrid ID="timesheetGrid" runat="server" GridLines="None" Skin="Windows7"AllowSorting="True" ShowGroupPanel="True" AutoGenerateColumns="False" AllowPaging="True"
    PageSize="15" ShowStatusBar="True" AllowFilteringByColumn="True" AllowMultiRowSelection="True"
    OnNeedDataSource="timesheetGrid_NeedDataSource" OnPreRender="timesheetGrid_PreRender"
    ViewStateMode="Enabled" onitemdatabound="timesheetGrid_ItemDataBound" Width="970px">
    <ClientSettings EnableRowHoverStyle="true" AllowColumnsReorder="True" ReorderColumnsOnClient="True"
        AllowDragToGroup="True">
        <Selecting AllowRowSelect="True" />
        <ClientEvents OnRowDblClick="RowDblClick" />
    </ClientSettings>
    <MasterTableView DataKeyNames="ID" EditMode="EditForms">
        <RowIndicatorColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
        </RowIndicatorColumn>
        <ExpandCollapseColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
        </ExpandCollapseColumn>
        <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
        <Columns>
            <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" />
            <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID" Visible="False"
                ReadOnly="true">
            </telerik:GridBoundColumn>
            <telerik:GridDateTimeColumn DataField="From" DataType="System.DateTime"
                HeaderText="Date" UniqueName="DateFrom" ReadOnly="true" DataFormatString="{0:dd/MM/yyyy}" FilterControlWidth="100px" HeaderStyle-Width="100px">
            </telerik:GridDateTimeColumn>
            <telerik:GridBoundColumn DataField="User.UserName" HeaderText="User" UniqueName="User"
                ReadOnly="true">
            </telerik:GridBoundColumn>
            <telerik:GridNumericColumn UniqueName="Duration" HeaderText="Duration" DataType="System.Double" HeaderStyle-Width="30px" FilterControlWidth="30px">
                <ItemStyle HorizontalAlign="Right"/>
            </telerik:GridNumericColumn>
            <telerik:GridBoundColumn DataField="Description" HeaderText="Description" UniqueName="Description">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DocketNo" HeaderText="Docket No" UniqueName="DocketNo"
                ReadOnly="true">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="FileCode" HeaderText="File Code" UniqueName="FileCode" HeaderStyle-Width="50px" FilterControlWidth="50px">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="FileCodeID" HeaderText="File Code ID" UniqueName="FileCodeID"
                Visible="false">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="CostCenter" HeaderText="Cost Center" UniqueName="CostCenter" HeaderStyle-Width="50px" FilterControlWidth="50px">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="CostCenterID" HeaderText="Cost Center ID" UniqueName="CostCenterID"
                Visible="false">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="CompanyID" HeaderText="Company ID" UniqueName="CompanyID"
                Visible="false">
            </telerik:GridBoundColumn>
            <telerik:GridCheckBoxColumn DataField="IsNegativeTimesheet" DataType="System.Boolean"
                HeaderText="Negative Timesheet" UniqueName="NegativeTimesheet" ReadOnly="true">
            </telerik:GridCheckBoxColumn>
            <telerik:GridCheckBoxColumn DataField="IsOvertime" DataType="System.Boolean" HeaderText="Overtime"
                UniqueName="Overtime" ReadOnly="true">
            </telerik:GridCheckBoxColumn>
        </Columns>
        <EditFormSettings UserControlName="UserControls/TimesheetEdit.ascx" EditFormType="WebUserControl">
            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
            </EditColumn>
        </EditFormSettings>
    </MasterTableView>
    <PagerStyle Mode="NumericPages" VerticalAlign="Bottom" />
    <FilterMenu EnableImageSprites="False">
    </FilterMenu>
    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Windows7">
    </HeaderContextMenu>
</telerik:RadGrid>


Column Calculation:
protected void timesheetGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem row = e.Item as GridDataItem;
        TimeSheet item = e.Item.DataItem as TimeSheet;
        if (item != null)
        {
            double duration = item.To.TimeOfDay.TotalHours - item.From.TimeOfDay.TotalHours;
            row["Duration"].Text = duration.ToString();
        }
        else
        {
            row["Duration"].Text = "0";
        }
    }
}

Exception:

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Expression cannot be null or empty.

Attached image.

Any help would be greatly appreciated.

Many thanks,
Daryl

2 Answers, 1 is accepted

Sort by
0
Alan
Top achievements
Rank 1
answered on 23 Feb 2011, 01:36 PM
Bump.
0
Alan
Top achievements
Rank 1
answered on 24 Feb 2011, 09:24 AM
Not needed anymore, worked around it by extending the entity framework class and creating a new property.
Tags
Grid
Asked by
Alan
Top achievements
Rank 1
Answers by
Alan
Top achievements
Rank 1
Share this question
or