Grouping on Complex Expressions

3 posts, 0 answers
  1. Brian Mains
    Brian Mains avatar
    485 posts
    Member since:
    Oct 2008

    Posted 25 Apr 2012 Link to this post

    Hello,

    In a RadGrid, I can have a column definition like the following:
    <asp:BoundColumn .. DataField="County.CountyName" />

    But I try this in a grid group by expression:
    <tel:GridGroupByExpression DataField="County.CountyName" />
    But this throws an exception.  Is there a way I can utilize these complex expressions for grouping?

    Thanks.

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Apr 2012 Link to this post

    Hi Brian Mains,

    I am not quite sure why you are using Asp BoundColumn. You cant add ASP Bound Column into RadGrid's column collection. I have tried Grouping with complex expression and it is working for me. Please take a look into following code snippet. And make sure that you have set RadGrid's EnableLinqExpressions property as false.

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
        EnableLinqExpressions="false">
        <MasterTableView>
            <GroupByExpressions>
                <telerik:GridGroupByExpression>
                    <GroupByFields>
                        <telerik:GridGroupByField FieldName="Stats.Downloads" />
                    </GroupByFields>
                    <SelectFields>
                        <telerik:GridGroupByField FieldName="Stats.Downloads" />
                    </SelectFields>
                </telerik:GridGroupByExpression>
            </GroupByExpressions>
            <Columns>
                <telerik:GridBoundColumn UniqueName="Id" DataType="System.Int32" DataField="Id" HeaderText="Id">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="Name" DataType="System.String" DataField="Name"
                    HeaderText="Name">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="Downloads" DataType="System.Int32" DataField="Stats.Downloads"
                    HeaderText="Downloads" DataFormatString="{0:n0}">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    C#:
    public ArrayList DataSource
    {
        get
        {
            object obj = Session["DataSource"];
            if (obj == null)
            {
                return new ArrayList();
            }
            return (ArrayList)obj;
        }
        set
        {
            Session["DataSource"] = value;
        }
    }
     
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ArrayList dataSource = new ArrayList();
            Statistics st = new Statistics();
            st.Downloads = 2;
            dataSource.Add(new Product() { Id = 1, Name = "aaa", Stats = st });
            dataSource.Add(new Product() { Id = 2, Name = "bbb", });
            this.DataSource = dataSource;
        }
    }
     
    protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        this.RadGrid1.DataSource = this.DataSource;
    }
     
    public class Product
    {
     
        public int Id { get; set; }
        public string Name { get; set; }
        public Statistics Stats { get; set; }
    }
     
    public class Statistics
    {
        public int Downloads { get; set; }
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Brian Mains
    Brian Mains avatar
    485 posts
    Member since:
    Oct 2008

    Posted 25 Apr 2012 Link to this post

    Shinu,

    Thanks very much.  I mistyped; I should have copied from my solution, as I do have Telerik's GridBoundColumn, not ASP.NET Bound column.  I have what you have, but for me it is complaining that "Stats.Downloads" is not available, in my scenario.  I'll have to look into it more then, it's good to know that it works.

    Thanks.
Back to Top