5.1 sp1 module display choice value in datagrid
I added a choices field to my module and want to display the value of this in a datagrid on my .ascx file.
The module is called Mitarbeiter (employees).
I found some related tables to this module on the database bud
a) did not figure out how that works
b) where all possible values are stored
c) how to get the value to display in the grid
This is my code for the grid. The part in Question is called Funktion.
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" AllowSorting="True" ShowGroupPanel="True" > <ClientSettings AllowDragToGroup="True"> </ClientSettings><MasterTableView><CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings><RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"><HeaderStyle Width="20px"></HeaderStyle></RowIndicatorColumn><ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"><HeaderStyle Width="20px"></HeaderStyle></ExpandCollapseColumn> <Columns> <telerik:GridBoundColumn DataField="Vorname" FilterControlAltText="Vorname" HeaderText="Vorname" UniqueName="Vorname"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Nachname" FilterControlAltText="Nachname" HeaderText="Nachname" UniqueName="Nachname"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Telefon" FilterControlAltText="Telefon" HeaderText="Telefon" UniqueName="Telefon"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Mail" FilterControlAltText="Email" HeaderText="E-Mail" UniqueName="Email"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Funktion" FilterControlAltText="Funktion" HeaderText="Funktion" UniqueName="Funktion"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Taetigkeit" FilterControlAltText="Taetigkeit" HeaderText="Tätigkeit" UniqueName="Taetigkeit"> </telerik:GridBoundColumn> </Columns><EditFormSettings><EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn></EditFormSettings></MasterTableView><FilterMenu EnableImageSprites="False"></FilterMenu></telerik:RadGrid>
This is my codebehind
namespace SitefinityWebApp.UserControls public partial class mitarbeiter_liste : System.Web.UI.UserControl protected void Page_Load(object sender, EventArgs e) if (!Page.IsPostBack) // Fetch a collection of "live" and "visible" mitarbeiter items. var myCollection = GetDataItems(); // Binds the collection of Person items to the RadGrid RadGrid1.DataSource = myCollection; RadGrid1.DataBind(); // Gets a collection of "live" and "visible" mitarbeiter items. public IQueryable<DynamicContent> GetDataItems() DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(); Type mitarbeiterType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Mitarbeiter.Mitarbeiter"); // Fetch a collection of "live" and "visible" mitarbeiter items. var myCollection = dynamicModuleManager.GetDataItems(mitarbeiterType).Where(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && i.Visible == true); return myCollection;
QUESTION 1
Any idea how I get the value of Funktion (see screenshot sf_funktion.png to display in the grid?
QUESTION 2
I could not find a table with all the possible values of the choise field. Any idea where they are stored, just out of curiosity.
Answer: Looking a bit throu the tables I found sf_mb_dynamic_module_field where the values are stored.
Markus
RadGrid's databinding does not understand array types for column values.
ChoiceField persist the values in a String[] by default, so in order to achieve the desired functionality you can easily use a GridTemplateColumn:
<telerik:GridTemplateColumn HeaderText="Choice" >
<ItemTemplate>
<asp:Literal ID="Funktion" runat="server" />
</ItemTemplate>
</telerik:GridTemplateColumn>
and then set the value of the control in your ItemTemplate on the server side:
void RGrdi1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
if (e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem || e.Item.ItemType == Telerik.Web.UI.GridItemType.Item)
var functionColumn = e.Item.FindControl("Funktion") as Literal;
var dataitem = e.Item.DataItem as DynamicContent;
var choiceValue = dataitem.GetValue<String[]>("TestChoice");
foreach (var item in choiceValue)
functionColumn.Text += item.ToString();