我想从API中获取下拉列表的文本值,我正在严重挣扎。umbraco数据类型和来自代码背后的文本值
这是我的时刻:
Document doc = new Document(Node.GetCurrent().Id);
doc.GetProperty("fieldPropertyName").Value;
这将返回ID为预置值的字符串表示。
我想要的是该预值的文本。
在此先感谢您的帮助。
我想从API中获取下拉列表的文本值,我正在严重挣扎。umbraco数据类型和来自代码背后的文本值
这是我的时刻:
Document doc = new Document(Node.GetCurrent().Id);
doc.GetProperty("fieldPropertyName").Value;
这将返回ID为预置值的字符串表示。
我想要的是该预值的文本。
在此先感谢您的帮助。
请原谅这是在VB中。
这是我发生在正在发展的语言。(我多么希望我可以使用C#)
Imports System.Runtime.CompilerServices
Imports umbraco.cms.businesslogic.web
Imports umbraco.cms.businesslogic.datatype
Module UmbracoExtensionHelper
<Extension()>
Public Function GetCustomPropertyValueFromPreValues(ByVal doc As Document, ByVal propertyName As String)
Dim returnValue As String = ""
Dim objProperty As umbraco.cms.businesslogic.property.Property = doc.getProperty(propertyName)
If objProperty IsNot Nothing Then
Dim objPreValues = PreValues.GetPreValues(objProperty.PropertyType.DataTypeDefinition.Id)
If objPreValues IsNot Nothing Then
''run through the ids of the datatypes and the value of the property
For Each entry As DictionaryEntry In objPreValues
Dim currentPreValue As PreValue = CType(entry.Value, PreValue)
If currentPreValue.Id.ToString().ToLower() = objProperty.Value.ToString().ToLower() Then
returnValue = currentPreValue.Value.ToLower()
Exit For
End If
Next
End If
End If
Return returnValue
End Function
End Module
我觉得你痛苦的人 – 2014-02-06 12:20:31
使用的库函数...
var stringValue = umbraco.library.GetPreValueAsString(Convert.ToInt32(doc.GetProperty("fieldName").Value));
使用下面的代码
aspx page
<asp:DropDownList ID="ddlLocation" ClientIDMode="Static" runat="server" AutoPostBack="true" CssClass="selectbox" OnSelectedIndexChanged="ddlLocation_SelectedIndexChanged" />
代码隐藏
var regionItems = regionFolder.Children;
if (regionItems.Count > 0) {
foreach (Node region in regionItems) {
if (region.GetProperty(FieldName.REGIONNAME) != null && !string.IsNullOrEmpty(region.GetProperty(FieldName.REGIONNAME).Value)) {
ddlLocation.Items.Add(new ListItem(region.GetProperty(FieldName.REGIONNAME).Value, region.Id.ToString()));
}
}
}
//ddlLocation.Items.Insert(0, "Choose");
ddlLocation.Items.Insert(0, new ListItem("Choose", "0"));
这里REGIONNAME =我们的字段名,
我已经找到一种方法通过遍历预值要做到这一点,但感觉有点klunky。没有人有更好的方法吗? – jimplode 2010-11-29 16:11:38