Sharepoint Web 部件列表组合框

发布于 2024-09-01 19:55:31 字数 149 浏览 6 评论 0原文

我有一个基于列表工作的 Web 部件,但我想要创建一个包含共享点列表列表的下拉列表,以便当用户编辑页面并选择“修改共享 Web 部件”时,他们可以选择一个列表item 并被解析回 web 部件。

任何示例或示例链接表示赞赏!

谢谢丹

I have a webpart that works off of a list but what I'm trying to do create a dropdown that contains a list of sharepoint lists so that when the user edits the page and selects 'modify shared webpart' they are able to choose a list item and that gets parsed back to the webpart.

Any examples or links to examples appreciated!

Thanks

Dan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

涫野音 2024-09-08 19:55:31

您正在寻找的东西称为“工具部件”。查看此示例以获取教程关于如何创建一个。

总的来说,您的一般步骤如下:

  1. 创建继承自 Microsoft.SharePoint.WebPartPages.ToolPart 的自定义 Toolpart 类
  2. 在您的自定义 Toolpart 中,重写 CreateChildControls,编写要迭代的代码SPWeb 中的列表,并将它们添加到 DropDownList
  3. 在您的 Web 部件中,覆盖 GetToolParts 并添加您的自定义 ToolPart,以便它显示在右侧

What you are looking for is called a Toolpart. Take a look at this example for a tutorial on how to create one.

Overall, your general steps will be:

  1. Create your custom Toolpart class inheriting from Microsoft.SharePoint.WebPartPages.ToolPart
  2. In your custom Toolpart, override CreateChildControls, write the code to iterate over the lists in your SPWeb, and add those to a DropDownList
  3. In your webpart, override GetToolParts and add your custom ToolPart so that it shows up in the right hand side
稍尽春風 2024-09-08 19:55:31

听起来您想创建一个自定义编辑器部分。在该部分中,您将有一个下拉列表显示列表的名称(您可能想要过滤隐藏列表和空列表),并且当从列表中选择一项时,第二个下拉列表将显示所选项目的“标题”列列表。

这里有一些代码(在此处编辑,因此需要清理)来帮助您开始:

protected Page_Load(...)
{
    if (IsPostBack) return;

    var web = SPContext.Current.Web;
    var query = from list in web.Lists
                where list.Hidden == false && list.ItemCount == 0
                select list;

    DropDownList1.DataSource = query;
    DropDownList1.DataTextField = "Title";
    DropDownList1.DataBind();
}

protected DropDownList1_SelectedIndexChanged(...)
{
    var web = SPContext.Current.Web;
    var listName = DropDownList1.Text;
    var list = web.Lists[listName];
    var table = list.Items.GetDataTable();
    DropDownList2.DataSource = table;
    DropDownList2.DataTextField = "Title";
    DropDownList2.DataValueField = "ID";
    DropDownList2.DataBind();
}

It sounds like you want to create a custom editor part. In the part you would have one dropdown that shows the names of the lists (you probably want to filter hidden and empty lists) and, when an item is selected from the list, a second dropdown shows the Title column of the items from the selected list.

Here's some code (edited here, so it will need to be cleaned up) to help you get started:

protected Page_Load(...)
{
    if (IsPostBack) return;

    var web = SPContext.Current.Web;
    var query = from list in web.Lists
                where list.Hidden == false && list.ItemCount == 0
                select list;

    DropDownList1.DataSource = query;
    DropDownList1.DataTextField = "Title";
    DropDownList1.DataBind();
}

protected DropDownList1_SelectedIndexChanged(...)
{
    var web = SPContext.Current.Web;
    var listName = DropDownList1.Text;
    var list = web.Lists[listName];
    var table = list.Items.GetDataTable();
    DropDownList2.DataSource = table;
    DropDownList2.DataTextField = "Title";
    DropDownList2.DataValueField = "ID";
    DropDownList2.DataBind();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文