I am using the built-in filtering on a RadGrid but I'm running into a problem with one column in particular. When I try to filter on the column in question, I get an "Object reference not set to an instance of an object" error and the filtering doesn't work. This particular column is generated from a subquery that's being used as a column expression (and then given an alias). It seems like the filtering only works for grid columns that have a matching column name in a database table (i.e. doesn't seem to work with columns generated from a subquery or UDF). Here is my aspx markup:
The column that I get the error on is the NomineeName column. Here is the C# codebehind:
And here is the NominationAdmin.cs file:
Any idea what's going on and how to fix it? Thanks.
<
telerik:RadGrid
ID
=
"grdAdmin"
runat
=
"server"
Width
=
"100%"
AllowFilteringByColumn
=
"True"
GridLines
=
"None"
AllowPaging
=
"True"
AllowSorting
=
"True"
AutoGenerateColumns
=
"False"
onneeddatasource
=
"grdAdmin_NeedDataSource"
PageSize
=
"20"
ondeletecommand
=
"grdAdmin_DeleteCommand"
>
<
GroupingSettings
CaseSensitive
=
"false"
/>
<
MasterTableView
DataKeyNames
=
"NominationID"
NoMasterRecordsText
=
"There are currently no nominations to display."
Width
=
"100%"
CommandItemDisplay
=
"Top"
AutoGenerateColumns
=
"False"
>
<
Columns
>
<
telerik:GridDateTimeColumn
DataField
=
"DateOfNomination"
DataFormatString
=
"{0:d}"
HeaderText
=
"Date Of Nomination"
SortExpression
=
"DateOfNomination"
UniqueName
=
"DateOfNomination"
ReadOnly
=
"true"
>
</
telerik:GridDateTimeColumn
>
<
telerik:GridBoundColumn
DataField
=
"NomineeName"
HeaderText
=
"Nominee Name"
SortExpression
=
"NomineeName"
DataType
=
"System.String"
UniqueName
=
"NomineeName"
ReadOnly
=
"true"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"NominatorName"
HeaderText
=
"Nominator Name"
SortExpression
=
"NominatorName"
DataType
=
"System.String"
UniqueName
=
"NominatorName"
ReadOnly
=
"true"
AllowFiltering
=
"false"
>
</
telerik:GridBoundColumn
>
<
telerik:GridButtonColumn
CommandName
=
"Delete"
Text
=
"Delete"
UniqueName
=
"DeleteCommandColumn"
ConfirmDialogType
=
"Classic"
ConfirmText
=
"Are you sure you want to delete this nomination from the database?"
ConfirmTitle
=
"Are you sure?"
>
</
telerik:GridButtonColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
The column that I get the error on is the NomineeName column. Here is the C# codebehind:
protected void grdAdmin_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
using (RecognitionEntities dc = new RecognitionEntities())
{
string selectStatement = string.Format(@"select n.NominationID,
n.DateOfNomination,
(SELECT FULL_NAME FROM dwdata.person_table where PERSON_ID=n.NomineeEmployeeID) as NomineeName,
(SELECT FULL_NAME FROM dwdata.person_table where PERSON_ID=n.NominatorEmployeeID) as NominatorName
from dbo.tblNominations as n
where (n.DeletedBy IS NULL)
and (n.FiscalYear = '{0}')",
ConfigurationManager.AppSettings["CurrentFiscalYear"]);
// bind the results to the grid
IEnumerable<
NominationAdmin
> pn = dc.ExecuteStoreQuery<
NominationAdmin
>(selectStatement);
grdAdmin.DataSource = pn.ToList();
}
}
And here is the NominationAdmin.cs file:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
Recognition.EntityDataModel
{
public
class
NominationAdmin
{
private
int
_nominationID;
private
DateTime _dateOfNomination;
private
string
_nomineeName;
private
string
_nominatorName;
public
int
NominationID
{
get
{
return
this
._nominationID; }
set
{
this
._nominationID = value; }
}
public
DateTime DateOfNomination
{
get
{
return
this
._dateOfNomination; }
set
{
this
._dateOfNomination = value; }
}
public
string
NomineeName
{
get
{
return
this
._nomineeName; }
set
{
this
._nomineeName = value; }
}
public
string
NominatorName
{
get
{
return
this
._nominatorName; }
set
{
this
._nominatorName = value; }
}
}
}
Any idea what's going on and how to fix it? Thanks.