【问题标题】:Retrieve SharePoint List Data and bind this to a dropdownlist检索 SharePoint 列表数据并将其绑定到下拉列表
【发布时间】:2011-01-01 05:44:40
【问题描述】:

我对 SharePoint 还很陌生,所以提前为听起来像“新手”而道歉。

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

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

请问各位好心人对如何实现这一点有任何想法吗?

非常感谢您,

灰 8-)

(附:祝大家新年快乐!)

【问题讨论】:

    标签: drop-down-menu web-parts ascx


    【解决方案1】:

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

    解决方法是将以下代码放在 .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

    谢谢,

    【讨论】:

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