I am struggling to create a series of templatefields in codebehind to a gridview. The datasource is an object which inside this object is another which is a List Object which has a series of properties. What I am trying to is display all of it in columns. Each element inside the List is to be a column and each of the values in the element to be displayed in the column. For example if I have 5 elements in the List, which has two values, then I want 5 columns and to display the two values.
Seaching I have found only examples based on database sources using ITemplate, which I have tried to use, but have failed to work.
Can anyome help?
MarkUp is simply
<asp:GridView runat="server" ID="grdvwMyTable" AutoGenerateColumns="false"/>
In the code behind, on the page load event on my custom control
MyObject obj = new MyObject();
MyMapper map = new MyMapper();
obj = map.MapObjects();
TemplateField dayOne = new TemplateField();
dayOne.HeaderText = obj.WeeklyShifts.Select(a=> a.StartTime)//<- Weekly Shifts is a List and Start Time is a property of this object.
dayOne.ItemTemplate = new AddTemplateToGridView(ListItemType.Item, obj.WeeklyShifts.Select(a=> a.ShiftName)// <- This is also part of the List object.
As you can see I am trying to create a column from a List Object. I have five elements inside my List Object called WeeklyShifts
which itself is part of obj. I want to have the start time as my header, and ShiftName
to in the column plus there will be some other values as well in that column, but I need to repeat this pattern 5 times, i.e for five days.