检索SharePoint列表数据并将其绑定到下拉列表 [英] Retrieve SharePoint List Data and bind this to a dropdownlist

查看:199
本文介绍了检索SharePoint列表数据并将其绑定到下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对SharePoint非常新颖,所以提前道歉,就像一个新手一样。



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



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



你有什么善意的人有什么想法可以实现吗?



提前非常感谢,



Ash 8 - )



(ps祝你新年快乐!)

解决方案

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



解决方案是将以下代码放在 .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; //列表字段保持值 - 第一列称为标题!
dropSite.DataTextField =标题; //列表栏名称显示在页面
dropSite.DataBind();
}
}
}

我在这里找到解决方案:



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



谢谢,



Ash


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 !)

解决方案

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

这篇关于检索SharePoint列表数据并将其绑定到下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆