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

filtering not working for column generated from subquery

1 Answer 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 25 Jan 2012, 09:50 PM
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:
<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.

1 Answer, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 30 Jan 2012, 01:13 PM
Hello Dave,

I have examined your code and I cannot see any difference between the NomineeName and the other columns. Is filtering working correct for them?
Here you can see the possible data-sources of the RadGrid and the List<T> is one of them.

If the issue persist, please open a formal support ticket and send us a sample project demonstrating the issue.

Greetings,
Mira
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Dave
Top achievements
Rank 1
Answers by
Mira
Telerik team
Share this question
or