【问题标题】:Can I add a third field to a .NET ListItem rendered object?我可以将第三个字段添加到 .NET ListItem 呈现的对象吗?
【发布时间】:2018-12-18 12:55:29
【问题描述】:

我不太喜欢 .NETSharePoint,并且我对将 Web 部件 工作到 SharePoint 2013 项目有以下疑问。

在我的 Web 部件中,我有一个这样的下拉列表:

DropDownList dropDownnEtichetta = new DropDownList();

然后我以这种方式将一些项目添加到这个 DropDownList 中:

for (int i = 0; i < etichettaCorrenteList.Items.Count; i++)
{
    dropDownnEtichetta.Items.Add(new ListItem(valoreDaMostrare, valoreId));
}

它工作正常,你可以看到 ListItem 被填充并传递下拉列表中显示的文本和值。

我想知道是否可以在此列表项中添加第三个信息。万一我该怎么办?

【问题讨论】:

    标签: c# .net sharepoint sharepoint-2013 selectlistitem


    【解决方案1】:
    https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.listitem.-ctor?view=netframework-4.7.2 
    

    表明 ListItem 没有采用三个字符串参数的构造器。它只有

    ListItem()  
    ListItem(String)    
    ListItem(String, String)    
    ListItem(String, String, Boolean)
    

    这些构造函数。

    出于您的目的,您可以扩展 ListItem 类。

    【讨论】:

      【解决方案2】:

      自己这样解决的:

      ListItem currentItem = new ListItem(valoreDaMostrare, valoreId);
      currentItem.Attributes.Add("valoreDaStampare", valoreDaStampare);
      
      dropDownnEtichetta.Items.Add(currentItem);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-12-28
        相关资源
        最近更新 更多