Silverlight DataGrid使用之一 显示篇(3)

2025-10-05

public DataGridControl() {

InitializeComponent();

SilverlightApplication1.ServiceReference1.Service1Client c = new ServiceReference1.Service1Client(); c.GetCDatasCompleted += new

EventHandler(c_GetCDatasCompleted);

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 GetCDatas(int pageindex,int pagesize); [OperationContract]

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 GetCDatas(int pageindex,int pagesize) {

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 CList=new List (); while (dr.Read())

{

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=\

Silverlight DataGrid使用之一 显示篇(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:对广播电视媒体受众群体的探析

相关阅读
本类排行
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 7

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219