We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Trying to use dynamic objects

Thread ID:

Created:

Updated:

Platform:

Replies:

116163 Apr 16,2014 05:43 AM UTC Apr 17,2014 04:02 AM UTC ASP.NET MVC (Classic) 1
loading
Tags: Grid
Rajiv Kumar
Asked On April 16, 2014 05:43 AM UTC

Hi ,
     We have a requirement in which the model would be dynamic and hence I tried to use dynamic (expandoobject) to create a dynamic object.I don't get error but the grid does not display anything other than the arrow key as shown in the attachment. Let me know if binding like that is possible or not if yes how.

Thanks,
Rajiv



Attachment: IssueWithDynamicObjects_65172c64.zip

Alan Sangeeth S [Syncfusion]
Replied On April 17, 2014 04:02 AM UTC

Hi Rajiv,

Thanks for using Syncfusion Products.

We would like to let you know that we have achieved your requirement “binding dynamic objects to Grid” by first converting the dynamic objects to Datatable and then we have binded it to Grid. Pease refer the following code snippets.

Code Snippet:

[CONTROLLER]

public static class Extn

{

public static DataTable ToDataTable(this IEnumerable<dynamic> items)

{

var data = items.ToArray();

if (data.Count() == 0) return null;

var dt = new DataTable();

foreach (var key in ((IDictionary<string, object>)data[0]).Keys)

{

dt.Columns.Add(key);

}

foreach (var d in data)

{

dt.Rows.Add(((IDictionary<string, object>)d).Values.ToArray());

}

return dt;

}

}

public ActionResult GridFeatures()

{

 

var obj = new PropertyDynamic();

obj.dynamicProperties = PropertyDynamic.GetDynamicProperties();

IEnumerable data = Extn.ToDataTable(obj.dynamicProperties).AsEnumerable();

return View(data);

}

For your convenience we have created a sample and the same can be downloaded from below link.

Sample:

http://www.syncfusion.com/downloads/support/directtrac/general/GridSample2-1516660105.zip

Please let us know if you need any further assistance.

Regards,
Alan Sangeeth S

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;