检索 SharePoint 列表数据并将其绑定到下拉列表

发布于 2024-08-16 08:27:56 字数 409 浏览 1 评论 0原文

我对 SharePoint 相当陌生,因此提前为听起来像“新手”而道歉。

我创建了一个简单的 Web 部件,它使用 Web 用户控件 - [.ascx 文件] 提供该 Web 部件的所有控件。在 .ascx 文件上,有一个 DropDownList,目前是硬编码的,并且在 Web 部件(在 SharePoint 站点内)中运行良好。

但是,我希望 .ascx 文件上的 DropDownList 绑定到 SharePoint 列表的特定列,以便当我更新 SharePoint 列表的该列时,DropDownList 自动反映更新。

请问各位好心人对如何实现这一目标有什么想法吗?

提前非常感谢您,

Ash 8-)

(祝大家新年快乐!)

I'm fairly new to SharePoint so apologies in advance for sounding like a 'Newbie'.

I have created a simple Webpart, which uses a Web User Control - [.ascx file] to provide all the controls for the Webpart. On the .ascx file, there is a DropDownList which is hard-coded at the moment and works well in the Webpart (within a SharePoint site).

However, I want the DropDownList on the .ascx file to be bound to a particular Column of a SharePoint List, so that when I update that column of the SharePoint List, the DropDownList reflects the update automatically.

Do any of you kind folk have any ideas on how to achieve this please?

Thank you very much in advance,

Ash 8-)

(p.s. Happy New Year to you All !)

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

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

发布评论

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

评论(1

乖乖 2024-08-23 08:27:56

我在发布上述文章(典型)后几分钟内找到了答案。

解决方案是将以下代码放在 .ascx.cs (代码隐藏)文件的 Page_Load 事件中:

if (!Page.IsPostBack)
        {
            using (SPSite site = new SPSite("http://yoursharepointsite"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["NameOfYourList"];
                    dropSite.DataSource = list.Items;
                    dropSite.DataValueField = "Title"; // List field holding value - first column is called Title anyway!
                    dropSite.DataTextField = "Title"; // List field holding name to be displayed on page 
                    dropSite.DataBind();
                }
            }
        }

我在这里找到了解决方案:

http://blogs .msdn.com/mattlind/archive/2008/02/12/bind-a-asp-dropdownlist-to-a-sharepoint-list.aspx

谢谢,

阿什

I found the answer within minutes of posting the above article (typical).

The solution is to place the following code in the Page_Load event of the .ascx.cs (code-behind) file:

if (!Page.IsPostBack)
        {
            using (SPSite site = new SPSite("http://yoursharepointsite"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["NameOfYourList"];
                    dropSite.DataSource = list.Items;
                    dropSite.DataValueField = "Title"; // List field holding value - first column is called Title anyway!
                    dropSite.DataTextField = "Title"; // List field holding name to be displayed on page 
                    dropSite.DataBind();
                }
            }
        }

I found the solution here:

http://blogs.msdn.com/mattlind/archive/2008/02/12/bind-a-asp-dropdownlist-to-a-sharepoint-list.aspx

Thanks,

Ash

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文