private void ShowAttributeValues() { phViewAttributes.Controls.Clear(); foreach (var attribute in Workflow.Attributes.OrderBy(a => a.Value.Order).Select(a => a.Value)) { var td = new TermDescription(); td.ID = "tdViewAttribute_" + attribute.Key; td.Term = attribute.Name; string value = Workflow.GetAttributeValue(attribute.Key); var field = attribute.FieldType.Field; string formattedValue = field.FormatValueAsHtml(phViewAttributes, value, attribute.QualifierValues); if (field is Rock.Field.ILinkableFieldType) { var linkableField = field as Rock.Field.ILinkableFieldType; td.Description = string.Format("<a href='{0}{1}'>{2}</a>", ResolveRockUrl("~"), linkableField.UrlLink(value, attribute.QualifierValues), formattedValue); } else { td.Description = formattedValue; } phViewAttributes.Controls.Add(td); } }
public static MvcHtmlString RadioButtonListFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, bool isInline, IDictionary <string, object> htmlAttributes = null) { ModelMetadata metadata = ModelMetadata.FromLambdaExpression <TModel, TProperty>(expression, htmlHelper.ViewData); var dataSource = TermDescription.GetDataFor(metadata.PropertyName); string name = ExpressionHelper.GetExpressionText(expression); var attributes = htmlHelper.GetUnobtrusiveValidationAttributes(name, metadata); if (htmlAttributes == null) { htmlAttributes = attributes; } else { foreach (var item in attributes) { htmlAttributes.Add(item); } } string fullHtmlFieldName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(name); string stateValue = (string)GetModelStateValue(htmlHelper, fullHtmlFieldName, typeof(string)); if (string.IsNullOrEmpty(stateValue)) { if (metadata.Model != null) { // 枚举值直接转换成整数,然后转成字符串 stateValue = ((int)metadata.Model).ToString(); } } return(GenerateHtml(fullHtmlFieldName, dataSource, isInline, htmlAttributes, stateValue)); }
void rptrActivities_ItemDataBound(object sender, RepeaterItemEventArgs e) { var activity = e.Item.DataItem as WorkflowActivity; if (activity != null) { var lblComplete = e.Item.FindControl("lblComplete") as Label; if (lblComplete != null) { lblComplete.Visible = activity.CompletedDateTime.HasValue; } var lblActive = e.Item.FindControl("lblActive") as Label; if (lblActive != null) { lblActive.Visible = !activity.CompletedDateTime.HasValue; } var tdAssignedToPerson = e.Item.FindControl("tdAssignedToPerson") as TermDescription; if (tdAssignedToPerson != null && activity.AssignedPersonAliasId.HasValue) { var person = _personAliasService.Queryable() .Where(a => a.Id == activity.AssignedPersonAliasId.Value) .Select(a => a.Person) .FirstOrDefault(); if (person != null) { tdAssignedToPerson.Description = string.Format("<a href='{0}{1}'>{2}</a>", ResolveRockUrl("~/Person/"), person.Id, person.FullName); } } var tdAssignedToGroup = e.Item.FindControl("tdAssignedToGroup") as TermDescription; if (tdAssignedToGroup != null && activity.AssignedGroupId.HasValue) { var group = _groupService.Get(activity.AssignedGroupId.Value); if (group != null) { tdAssignedToGroup.Description = group.Name; } } var tdActivated = e.Item.FindControl("tdActivated") as TermDescription; if (tdActivated != null && activity.ActivatedDateTime.HasValue) { tdActivated.Description = string.Format("{0} {1} ({2})", activity.ActivatedDateTime.Value.ToShortDateString(), activity.ActivatedDateTime.Value.ToShortTimeString(), activity.ActivatedDateTime.Value.ToRelativeDateString()); } var tdCompleted = e.Item.FindControl("tdCompleted") as TermDescription; if (tdCompleted != null && activity.CompletedDateTime.HasValue) { tdCompleted.Description = string.Format("{0} {1} ({2})", activity.CompletedDateTime.Value.ToShortDateString(), activity.CompletedDateTime.Value.ToShortTimeString(), activity.CompletedDateTime.Value.ToRelativeDateString()); } var phActivityAttributes = e.Item.FindControl("phActivityAttributes") as PlaceHolder; if (phActivityAttributes != null) { foreach (var attribute in activity.Attributes.OrderBy(a => a.Value.Order).Select(a => a.Value)) { var td = new TermDescription(); phActivityAttributes.Controls.Add(td); td.Term = attribute.Name; string value = activity.GetAttributeValue(attribute.Key); var field = attribute.FieldType.Field; string formattedValue = field.FormatValueAsHtml(phActivityAttributes, value, attribute.QualifierValues); if (field is Rock.Field.ILinkableFieldType) { var linkableField = field as Rock.Field.ILinkableFieldType; td.Description = string.Format("<a href='{0}{1}'>{2}</a>", ResolveRockUrl("~"), linkableField.UrlLink(value, attribute.QualifierValues), formattedValue); } else { td.Description = formattedValue; } phActivityAttributes.Controls.Add(td); } } var gridActions = e.Item.FindControl("gridActions") as Grid; if (gridActions != null) { gridActions.DataSource = activity.Actions.OrderBy(a => a.ActionType.Order) .Select(a => new { Name = a.ActionType.Name, LastProcessed = a.LastProcessedDateTime.HasValue ? string.Format("{0} {1} ({2})", a.LastProcessedDateTime.Value.ToShortDateString(), a.LastProcessedDateTime.Value.ToShortTimeString(), a.LastProcessedDateTime.Value.ToRelativeDateString()) : "", Completed = a.CompletedDateTime.HasValue, CompletedWhen = a.CompletedDateTime.HasValue ? string.Format("{0} {1} ({2})", a.CompletedDateTime.Value.ToShortDateString(), a.CompletedDateTime.Value.ToShortTimeString(), a.CompletedDateTime.Value.ToRelativeDateString()) : "" }) .ToList(); gridActions.DataBind(); } } }
/// <summary> /// /// </summary> /// <param name="htmlHelper"></param> /// <param name="name"></param> /// <param name="typeName">在TermDescriptions类中定义的静态属性名称</param> /// <param name="isInline"></param> /// <param name="htmlAttributes"></param> /// <param name="selectedValue"></param> /// <returns></returns> public static MvcHtmlString RadioButtonList(this HtmlHelper htmlHelper, string name, string typeName, bool isInline, IDictionary <string, object> htmlAttributes = null, string selectedValue = null) { var dataSource = TermDescription.GetDataFor(typeName); return(GenerateHtml(name, dataSource, isInline, htmlAttributes, selectedValue)); }