silverlight   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了silverlight使用DataPager实现DataGrid分页大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

1)前台代码 <UserControl x:Class="SilverlightApplication70.MainPage" xmlns="http://scheR_79_11845@as.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://scheR_79_11845@as.microsoft.com/winfx/2006/xaml" xml
@H_419_4@

1)前台代码

<UserControl x:Class="SilverlightApplication70.MainPage"
    xmlns="http://scheR_79_11845@as.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://scheR_79_11845@as.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://scheR_79_11845@as.microsoft.com/expression/blend/2008"
    xmlns:mc="http://scheR_79_11845@as.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data">


    <Grid x:Name="LayoutRoot" BACkground="White">
        <!--用StackPanel解决DataGrid和DataPager绑定之后,DataGrid行无法选中。-->
        <StackPanel Orientation="Vertical">
        <data:DataGrid Name="TestDataGrid" AutoGeneratecolumns="false">
            <data:DataGrid.columns>
                <data:DataGridTextcolumn Header="studentID" Binding="{Binding studentID}">
                </data:DataGridTextcolumn>
                <data:DataGridTextcolumn Header="studentName" Binding="{Binding studentNamE}">
                </data:DataGridTextcolumn>
            </data:DataGrid.columns>
        </data:DataGrid>
        <data:DataPager Name="TestDataPager"/>
        </StackPanel>
    </Grid>
</UserControl>

2)后台代码

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;


namespace SilverlightApplication70
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }


        void MainPage_Loaded(object sender,RoutedEventArgs E)
        {
            List<student> items=Getstudents();
            System.Windows.Data.PagedCollectionView pagedCollectionView = new System.Windows.Data.PagedCollectionView(items);
            pagedCollectionView.PageSize = 5;
            TestDataGrid.Itemssource = pagedCollectionView;
            TestDataPager.source = pagedCollectionView;
        }
        /// <sumMary>
        /// 获取数据源
        /// </sumMary>
        /// <returns></returns>
        private List<student> Getstudents()
        {
            List<student> items = new List<student>();
            for (int i = 0; i < 20; i++)
            { 
                items.Add(new student(i,"张三"+i));
            }
            return items;
        }
    }


    public class student
    {
        public student(){ }
        public student(int _studentID,String _studentName)
        {
            this.studentID = _studentID;
            this.studentName = _studentName;
        }
        privatE int studentID;


        public int studentID
        {
            get { return studentID; }
            set { studentID = value; }
        }
        private String studentName;


        public String studentName
        {
            get { return studentName; }
            set { studentName = value; }
        }
    }
}


3)个人小结

silverlight使用DataPager实现DataGrid分页是客户端分页,在客户端选择上一页下一页时是不会连接数据库的。

@H_419_4@
@H_419_4@
@H_419_4@

大佬总结

以上是大佬教程为你收集整理的silverlight使用DataPager实现DataGrid分页全部内容,希望文章能够帮你解决silverlight使用DataPager实现DataGrid分页所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。