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

Casting DynamicClass from OpenAccessLinqDataSource

2 Answers 57 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chris
Top achievements
Rank 1
Chris asked on 15 Aug 2012, 03:47 PM
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">
    <WhereParameters>
        <asp:Parameter DefaultValue="1" Name="Enabled" Type="Int16" />
    </WhereParameters>
</telerik:OpenAccessLinqDataSource>

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 Answers, 1 is accepted

Sort by
0
Accepted
Damyan Bogoev
Telerik team
answered on 16 Aug 2012, 03:11 PM
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.

Regards,
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!
0
Chris
Top achievements
Rank 1
answered on 16 Aug 2012, 09:07 PM
Thank you so much. I went with reflection and it worked great! The sample project was very helpful.
Tags
Development (API, general questions)
Asked by
Chris
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Chris
Top achievements
Rank 1
Share this question
or