public DataGridControl() {
InitializeComponent();
SilverlightApplication1.ServiceReference1.Service1Client c = new ServiceReference1.Service1Client(); c.GetCDatasCompleted += new
EventHandler
c.GetCDatasAsync(); }
void c_GetCDatasCompleted(object sender, ServiceReference1.GetCDatasCompletedEventArgs e) {
if (e.Error == null) {
System.Windows.Data.PagedCollectionView view = new System.Windows.Data.PagedCollectionView(e.Result); view.Filter = (o) => {
CData c = o as CData; return c.id % 5 == 0; //过滤条件 };
dataGrid1.ItemsSource = view; } }
如果需要服务器数据库上过滤条件数据 首先在sl输入好条件然后用wcf发送到服务器上 用sql的where 返回一个列表 需要wcf定义一个过滤方法 看需求过滤什么条件 就可以了 思路和更新行没什么区别的
查看文章
Silverlight DataGrid使用之五 分页篇 2011-06-07 23:01
用Silverlight提供分页特性参考
http://hi.http://www.wodefanwen.com//mldark/blog/item/cbbdc3c30ffe5f21e4dd3bc4.html这
个文章
接下来讲解用服务端分页合适上万数据使用 首先在数据库创建一个表 随便取名
然后创建一个存储过程 取名DataGridPages
CreatePROCEDURE [dbo].[DataGridPages] (@pageindex int,@pagesize int ) AS BEGIN
with pages as (
SELECT id,text,ROW_NUMBER()over(order by id)as pageindex FROM dbo.t1 )
SELECT * FROM pages
where pageindex between(@pageindex*@pagesize)+1 and (@pageindex+1)*@pagesize END
我用的是sqlserver2008版本 创建好了 然后在wcf创建类型 cs代码
namespace WcfService1 {
// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配
置文件中的接口名“IService1”。 [ServiceContract]
public interface IService1 {
[OperationContract]
List
int PageCount(int pagesize); // TODO: 在此添加您的服务操作 }
// 使用下面示例中说明的数据协定将复合类型添加到服务操作 [DataContract]
public class CData {
[DataMember] public int id; [DataMember]
public string text; }
[System.ServiceModel.Activation.AspNetCompatibilityRequirements(RequirementsMode =
System.ServiceModel.Activation.AspNetCompatibilityRequirementsMode.Required)]
public class Service1 : IService1 {
public List
SqlConnection cn = new
SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings[\ SqlCommand cmd=new SqlCommand (\ cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue(\ cmd.Parameters.AddWithValue(\ cn.Open();
SqlDataReader dr=cmd.ExecuteReader( ); List
{
CData c = new CData { id =
int.Parse(dr[\ CList.Add(c); }
cn.Close(); return CList; }
public int PageCount(int pagesize) {
SqlConnection cn = new
SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings[\
SqlCommand cmd=new SqlCommand (\t1\
cn.Open();
int count =int.Parse( cmd.ExecuteScalar().ToString()); cn.Close();
if (count % pagesize == 0)//如果有余数的话+1 return count / pagesize; else
return count / pagesize + 1; } } 在xaml代码
HorizontalAlignment=\Width=\ CanUserSort=\
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 SilverlightApplication1.ServiceReference1; namespace SilverlightApplication1 {
public partial class DataGridControl : UserControl {
int currentIndex = 0;//当前素引 int pagesize = 5;//每页项数