Casting DynamicClass from OpenAccessLinqDataSource

Thread is closed for posting
3 posts, 1 answers
  1. Chris
    Chris avatar
    13 posts
    Member since:
    Oct 2010

    Posted 15 Aug 2012 Link to this post

    Hello, using RadComboBox I want to add some attributes from the OpenAccessLinqDataSource that populates it on the DataBound event. The DataItem looks good but I can't figure out what to cast the DynamicClass to! Doh.

    ASPX DataSource
    <telerik:OpenAccessLinqDataSource ID="OAL_Stock_Topic" runat="server"
        ContextTypeName="Flow.Financials_ST2" EntityTypeName=""
        ResourceSetName="Stock_topics" Select="new (ID, Market, IsIndex, IsHolidayClosed)"
        Where="Enabled == @Enabled">
            <asp:Parameter DefaultValue="1" Name="Enabled" Type="Int16" />

    c# for DataBound Event
    protected void MarketItemDataBound(object o, RadComboBoxItemEventArgs e)
        // Does this work? No :(
        Stock_topic st = e.Item.DataItem as Stock_topic;
        // Silly guesses
        var st2 = e.Item.DataItem as Flow.Financials_ST2;
        var st3 = e.Item.DataItem as OpenAccessLinqDataSource;
        // the goal
        e.Item.Attributes["IsIndex"] = "Index Here";
        e.Item.Attributes["IsHolidayClosed"] = "Closed Status Here";

    See attached file re: DataItem has data
  2. Answer
    Damyan Bogoev
    Damyan Bogoev avatar
    581 posts

    Posted 16 Aug 2012 Link to this post

    Hi Chris,

    I have prepared a sample application which demonstrates two different approaches in order to achieve the desired goal.

    Approach 1 is using a reflection to find the property and set a new value to it.

    Approach 2 is using a view which represents the entity projection.

    Hope that helps. If any other questions arise, do not hesitate to contact us back.

    Damyan Bogoev
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
  3. Chris
    Chris avatar
    13 posts
    Member since:
    Oct 2010

    Posted 16 Aug 2012 Link to this post

    Thank you so much. I went with reflection and it worked great! The sample project was very helpful.
Back to Top