【问题标题】:display list data in textblock verses datagrid, sharepoint webpart在 textblock 与 datagrid、sharepoint webpart 中显示列表数据
【发布时间】:2011-07-09 02:58:22
【问题描述】:

我正在构建一个 Silverlight 网络部件。我只是想在文本块中显示共享点列表数据而不是数据网格,因为我只打算从列表中返回一项。我已经设法在数据网格中获得了我想要的结果,但我不确定如何修改我的代码,以便我可以在文本块中显示我的数据。

我认为我可以简单地写

texblock1.text = projects;

但它会引发错误。

这是我的 xaml 主页背后的代码-------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.SharePoint.Client;

namespace something{         

    public class Project{        
        public string Title {get; set;}        
    }     

    public partial class MainPage : UserControl    
    {        
        public string SiteUrl { get; set; }        

        private ListItemCollection _projects;        

        //private Web _web = null;        
        //private string _lastErrorMessage = null;        

        public MainPage()        
        {            

            InitializeComponent();
            ClientContext context = new ClientContext(ApplicationContext.Current.Url);
            context.Load(context.Web);
            List Projects = context.Web.Lists.GetByTitle("projects");
            context.Load(Projects);
            CamlQuery query = new Microsoft.SharePoint.Client.CamlQuery();

            string camlQueryXml = "<View><Query><Where><Eq><FieldRef Name=\"NameLast\" /><Value Type=\"Boolean\">1</Value></Eq></Where></Query></View>"; 

            query.ViewXml = camlQueryXml;
            _projects = Projects.GetItems(query);
            context.Load(_projects);context.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(OnRequestSucceeded), null);         

        }        

        private void OnRequestSucceeded(Object sender, ClientRequestSucceededEventArgs args)        
        {            

            // This is not called on the UI thread.            
            Dispatcher.BeginInvoke(BindData);        
        }        

        private void BindData()        
        {            

            List<Project> projects = new List<Project>();            

            foreach (ListItem li in _projects)            

            {                

                projects.Add(new Project()                

                {                    
                    Title = li["Title"].ToString(),  
                });            

            }            

            dataGrid1.ItemsSource = projects; // must be on UI thread        
        }    
    }
}

【问题讨论】:

    标签: sharepoint-2010 web-parts


    【解决方案1】:

    要在 UI 线程中运行代码,请使用如下代码:

    Dispatcher.BeginInvoke(() => {
        //add code here to which are to be executed on the UI thread
    });
    

    【讨论】:

    • 我们将不胜感激!感谢您的意见。
    猜你喜欢
    • 2021-01-16
    • 1970-01-01
    • 2023-03-17
    • 2014-10-28
    • 2011-05-19
    • 2011-12-14
    • 2011-09-30
    • 2010-11-19
    • 1970-01-01
    相关资源
    最近更新 更多