Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 84751

Creating Grid with unknown columns

$
0
0

Hello Tyler,

The cause for the error is how the C# captures scope variable. In the code you have pasted, the c variable value is incremented thus all of the expression used in the column Bound method will point to the last value of the c. In order to correct this you should use a local variable which will hold the exact value of the c at the point of creation of the Bound method. Similar to the following:

for (int c = 0; c < ViewBag.RoleCount; c++)
{
  var idx = c;
  columns.Bound(r => r.Roles[idx].RoleVal).Title(ViewBag.Roles[c]);
}
Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 

Viewing all articles
Browse latest Browse all 84751

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>