首页 > 解决方案 > 如何将用户选择的值存储到由 SharePoint Web 部件呈现的 n DropDown 中?

问题描述

我是.NET* 和 **SharePoint的新手,我遇到了以下问题。

我正在开发一个Web 部件(到 Share Point 2013 中),它检索 n SharePoint 列表(这些列表的数量是可变的,它不是固定数字)并使用这些列表的内容来呈现 n DropDown(这些下拉列表的内容down 是相关 SharePoint 列表的内容)。

所以基本上进入我的 Web 部件的Page_Load()方法,我有这样的东西(它有效):

else if (mode != null && mode.Equals("scelta_campi_facoltativi_etichetta"))
{

    SPList listaCampiOpzionaliEtichetta = contextWeb.Lists["ListaCampiOpzionaliEtichetta"];

    String tipoDocumentiInternalName = listaCampiOpzionaliEtichetta.Fields["TipoDocumento"].InternalName;
    Clausola c = null;

    if (tipoDoc.Equals("docEntrata"))
    { 
        c = new Clausola(Clausola.condizione.Eq, Clausola.tipoCampo.Choice, Clausola.CondizioneExtra.no, "Entrata", tipoDocumentiInternalName);
    }
    else if(tipoDoc.Equals("docUscita"))
    {
        c = new Clausola(Clausola.condizione.Eq, Clausola.tipoCampo.Choice, Clausola.CondizioneExtra.no, "Uscita", tipoDocumentiInternalName);
    }

    string q = Query.creaQueryWhere(c.query);
    SPQuery queryQ = new SPQuery();
    queryQ.Query = q;

    SPListItemCollection etichetteCollection = listaCampiOpzionaliEtichetta.GetItems(queryQ);

    Table table = new Table();
    table.CellPadding = 2;
    table.CellSpacing = 2;
    table.Width = Unit.Percentage(100);

    foreach (SPListItem item in etichetteCollection)
    {
        Debug.WriteLine("etichetta: " + item["NomeLista"] + " URL sito: " + item["UrlSito"]);

        SPSite sitoEtichettaCorrente = new SPSite(item["UrlSito"].ToString());  // Top level website of the site collection
        SPWeb currentWebSite = sitoEtichettaCorrente.OpenWeb();

        //SPList eitchettaCorrenteList =  currentWebSite.GetList(item["NomeLista"].ToString());

        SPList eitchettaCorrenteList = currentWebSite.Lists[item["NomeLista"].ToString()];

        String nomeColonna = item["NomeColonna"].ToString();
        String codice = item["Codice"].ToString();

        TableRow rigaCorrente = new TableRow();

        TableCell cell1Corrente = new TableCell();
        TableCell cell2Corrente = new TableCell();

        cell1Corrente.Controls.Add(new LiteralControl((String)item["NomeLista"]));

        DropDownList dropDownnEtichetta = new DropDownList();
        for (int i = 0; i < eitchettaCorrenteList.Items.Count; i++)
        {

            dropDownnEtichetta.CssClass = "chosen-select";
            dropDownnEtichetta.ClientIDMode = ClientIDMode.Static;
            dropDownnEtichetta.ID = (String)item["NomeLista"];

            string valoreDaMostrareInternalName = eitchettaCorrenteList.Fields[nomeColonna].InternalName;
            string valoreDaStampareInternalName = eitchettaCorrenteList.Fields[codice].InternalName;

            string valoreDaMostrare = eitchettaCorrenteList.Items[i].GetFormattedValue(valoreDaMostrareInternalName);
            string valoreDaStampare = eitchettaCorrenteList.Items[i].GetFormattedValue(valoreDaStampareInternalName);

            dropDownnEtichetta.Items.Add(new ListItem(valoreDaMostrare, valoreDaStampare));

            cell2Corrente.Controls.Add(dropDownnEtichetta);

            rigaCorrente.Controls.Add(cell1Corrente);
            rigaCorrente.Controls.Add(cell2Corrente);


        }

        table.Controls.Add(rigaCorrente);

    }
    sceltaCampiEtichettaPanel.Controls.Add(table);

    HtmlGenericControl buttondiv = new HtmlGenericControl("div");

    Button bottoneConfermaCampiFacoltativiEtichetta = new Button();
    bottoneConfermaCampiFacoltativiEtichetta.Text = "Conferma";
    bottoneConfermaCampiFacoltativiEtichetta.CssClass = "shiny-blue";
    //bottoneConfermaCampiFacoltativiEtichetta.OnClientClick = "return validatePwd();";
    //bottoneConfermaCampiFacoltativiEtichetta.Click += ButtonSalva_Click;

    buttondiv.Controls.Add(new LiteralControl("<br/>"));
    buttondiv.Controls.Add(bottoneConfermaCampiFacoltativiEtichetta);

    sceltaCampiEtichettaPanel.Controls.Add(buttondiv);
}

如您所见,我正在检索 SharePoint 列表的列表。我在每个列表上进行迭代,并使用相关当前列表的内容填充呈现的 DropDown 的竞争。

现在我的问题是:用户可以从这些DropDown中选择一个值。我想将用户选择的值(可能在类级别)存储到这些下拉列表中。

实施这项任务的明智策略是什么?

标签: c#.netsharepointsharepoint-2013web-parts

解决方案


推荐阅读