/// <summary> /// Binds to the values of a definedType /// </summary> /// <param name="listControl">The list control.</param> /// <param name="definedType">Type of the defined.</param> public static void BindToDefinedType(this ListControl listControl, Rock.Web.Cache.DefinedTypeCache definedType) { var ds = definedType.DefinedValues .Select(v => new { v.Name, v.Id }); listControl.DataSource = ds; listControl.DataTextField = "Name"; listControl.DataValueField = "Id"; listControl.DataBind(); }
/// <summary> /// Binds to the values of a definedType using the definedValue's Id as the listitem value /// </summary> /// <param name="listControl">The list control.</param> /// <param name="definedType">Type of the defined.</param> /// <param name="insertBlankOption">if set to <c>true</c> [insert blank option].</param> /// <param name="useDescriptionAsText">if set to <c>true</c> [use description as text].</param> public static void BindToDefinedType(this ListControl listControl, Rock.Web.Cache.DefinedTypeCache definedType, bool insertBlankOption = false, bool useDescriptionAsText = false) { var ds = definedType.DefinedValues .Select(v => new { Name = v.Value, v.Description, v.Id }); listControl.SelectedIndex = -1; listControl.DataSource = ds; listControl.DataTextField = useDescriptionAsText ? "Description" : "Name"; listControl.DataValueField = "Id"; listControl.DataBind(); if (insertBlankOption) { listControl.Items.Insert(0, new ListItem()); } }