代码之家  ›  专栏  ›  技术社区  ›  jimplode

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

  •  1
  • jimplode  · 技术社区  · 15 年前

    我正试图从API中获取下拉列表的文本值,我正在认真地挣扎。

    这就是我现在所拥有的:

    Document doc = new Document(Node.GetCurrent().Id);
    
    doc.GetProperty("fieldPropertyName").Value;
    

    这将返回前一个值的id的字符串表示形式。

    我想要的是那个预设值的文本。

    提前谢谢你的帮助。

    3 回复  |  直到 15 年前
        1
  •  4
  •   Pete - MSFT    15 年前

    使用库函数。。。

    var stringValue = umbraco.library.GetPreValueAsString(Convert.ToInt32(doc.GetProperty("fieldName").Value));
    
        2
  •  0
  •   jimplode    15 年前

    请原谅我在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
    
        3
  •  0
  •   Ankit Agrawal    12 年前

    使用以下代码

    aspx页

     <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=我们的域名,