来自代码隐藏的umbraco数据类型和文本值

来自代码隐藏的umbraco数据类型和文本值,umbraco,Umbraco,我正试图从API中获取下拉列表的文本值,我正在努力 这就是我目前的情况: Document doc = new Document(Node.GetCurrent().Id); doc.GetProperty("fieldPropertyName").Value; 这将返回prevalue的id的字符串表示形式 我想要的是该pre值的文本 提前感谢您的帮助。请原谅这是在VB中 这就是我发展的语言。我多么希望我能用C Imports System.Runtime.CompilerServices

我正试图从API中获取下拉列表的文本值,我正在努力

这就是我目前的情况:

Document doc = new Document(Node.GetCurrent().Id);

doc.GetProperty("fieldPropertyName").Value;
这将返回prevalue的id的字符串表示形式

我想要的是该pre值的文本


提前感谢您的帮助。

请原谅这是在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

请原谅这是在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

使用库函数

var stringValue = umbraco.library.GetPreValueAsString(Convert.ToInt32(doc.GetProperty("fieldName").Value));

使用库函数

var stringValue = umbraco.library.GetPreValueAsString(Convert.ToInt32(doc.GetProperty("fieldName").Value));
使用以下代码

aspx页

 <asp:DropDownList ID="ddlLocation" ClientIDMode="Static" runat="server" AutoPostBack="true" CssClass="selectbox" OnSelectedIndexChanged="ddlLocation_SelectedIndexChanged" />
这里REGIONNAME=我们的字段名,

使用以下代码

aspx页

 <asp:DropDownList ID="ddlLocation" ClientIDMode="Static" runat="server" AutoPostBack="true" CssClass="selectbox" OnSelectedIndexChanged="ddlLocation_SelectedIndexChanged" />

这里REGIONNAME=我们的字段名,

我找到了一种方法,通过在pre值上循环来实现这一点,但感觉有点笨拙。没有人有更好的方法吗?我已经找到了一种方法,通过循环预先设置的值来实现这一点,但感觉有点笨拙。没有人有更好的方法吗?