Silverlight以列表显示数据库数据_DataGrid
效果图:

前台代码:
里面有一部分是我测试统计图的代码,不想改,感觉应该不影响理解....
<UserControl x:Class="Task_One.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
xmlns:vc="clr-namespace:Visifire.Charts;assembly=SLVisifire.Charts"
mc:Ignorable="d"
d:DesignHeight="700" d:DesignWidth="1400" > <Grid x:Name="LayoutRoot1" Background="AliceBlue">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<!--<Grid Grid.Row="0">
<Button Content="Button" HorizontalAlignment="Left" Margin="188,17,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/>
<TextBox x:Name="myText" HorizontalAlignment="Left" Height="23" Margin="10,17,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="143"/>
<TextBox x:Name="text18" HorizontalAlignment="Left" Height="23" Margin="430,16,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="text30" HorizontalAlignment="Left" Height="23" Margin="643,16,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="text40" HorizontalAlignment="Left" Height="23" Margin="858,16,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/> <TextBlock HorizontalAlignment="Left" Margin="358,20,0,0" TextWrapping="Wrap" Text="18岁占比:" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Margin="569,20,0,0" TextWrapping="Wrap" Text="30岁占比:" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Margin="795,20,0,0" TextWrapping="Wrap" Text="40岁占比:" VerticalAlignment="Top"/>
<Button Content="修改" HorizontalAlignment="Left" Margin="1014,17,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_2"/>
</Grid>-->
<Grid x:Name="LayoutRoot" Grid.Row="1" Background="AntiqueWhite"> <my:DataGrid AutoGenerateColumns="False" HorizontalAlignment="Left" Name="dgList" Width="250" Margin="10,10,0,60">
<my:DataGrid.Columns>
<my:DataGridTextColumn Header="ID" Binding="{Binding ID,Mode=OneWay}" Width="80"></my:DataGridTextColumn>
<my:DataGridTextColumn Header="手机号" Binding="{Binding WORKSTATION,Mode=OneWay}" Width="150"></my:DataGridTextColumn> </my:DataGrid.Columns>
</my:DataGrid> <vc:Chart Grid.Row="0" Name="chtChartOne" Height="300" Width="500">
<vc:Chart.AxesY>
<!--Y间隔-->
<vc:Axis Interval="20" Suffix="%"/>
</vc:Chart.AxesY>
</vc:Chart> </Grid> </Grid>
</UserControl>
后台代码:
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 System.Collections.ObjectModel;
using Task_One.ServiceReference1;
using System.Reflection;
using Visifire.Charts; //因为要用到Assembly,所以引入此空间 namespace Task_One
{ public partial class MainPage : UserControl
{ public MainPage()
{
_YV18 = new Random().Next();
_YV30 = new Random().Next();
_YV40 = new Random().Next(); InitializeComponent();
InitPage(); }
private void client_GetDatabyNameCompleted(object sender, GetDatabyNameCompletedEventArgs e)
{ System.Collections.ObjectModel.ObservableCollection<ServiceReference1.Class1> temp = new ObservableCollection<ServiceReference1.Class1>(); temp = e.Result;
dgList.ItemsSource = temp;
//for (int i = 0; i < temp.Count; i++)
//{ // MessageBox.Show(temp[i].ID.ToString() + " and " + temp[i].WORKSTATION.ToString());
//}
} private void Button_Click_1(object sender, RoutedEventArgs e)
{ Task_One.ServiceReference1.ServiceClient client = new Task_One.ServiceReference1.ServiceClient(); client.GetDatabyNameAsync(Convert.ToInt32(myText.Text.ToString())); client.GetDatabyNameCompleted += new EventHandler<GetDatabyNameCompletedEventArgs>(client_GetDatabyNameCompleted); client.CloseAsync();
} #region 柱状图示例
/// <summary>
/// 画柱状图
/// </summary>
public void InitPage()
{
chtChartOne.Series.Clear(); chtChartOne.View3D = true;
//Title title = new Title(); //title.Text = "柱状图的标题内容";
//chtChartOne.Titles.Add(title); //统计资料列
DataSeries ds = new DataSeries();
//柱状类型
ds.RenderAs = RenderAs.StackedColumn;
//显示Lable
ds.LabelStyle = LabelStyles.OutSide;
ds.LabelEnabled = true;
//栏
ds.DataPoints.Add(new DataPoint() { AxisXLabel = "18-29岁", YValue = YV18 });
ds.DataPoints.Add(new DataPoint() { AxisXLabel = "30-39岁", YValue = YV30 });
ds.DataPoints.Add(new DataPoint() { AxisXLabel = "40-49岁", YValue = YV40 });
ds.DataPoints.Add(new DataPoint() { AxisXLabel = "50-64岁", YValue = 18.9 });
ds.DataPoints.Add(new DataPoint() { AxisXLabel = "65岁以上", YValue = 17.2 });
chtChartOne.Series.Add(ds);
}
#endregion /// <summary>
/// 修改比例值
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button_Click_2(object sender, RoutedEventArgs e)
{
YV18 = Convert.ToInt32(text18.Text.ToString()); if (Convert.ToInt32(text30.Text.ToString()) >= )
{
YV30 = Convert.ToInt32(text30.Text.ToString());
}
else
{
YV30 = ;
}
if (Convert.ToInt32(text40.Text.ToString())>=)
{
YV40 = Convert.ToInt32(text40.Text.ToString());
}
else
{
YV40 = ;
} InitPage(); } private Int32 _YV18;
private Int32 _YV30;
private Int32 _YV40; public Int32 YV18
{
get { return _YV18; }
set { _YV18 = value; }
}
public Int32 YV30
{
get { return _YV30; }
set { _YV30 = value; }
}
public Int32 YV40
{
get { return _YV40; }
set { _YV40 = value; }
} } }
源码:http://pan.baidu.com/s/1o6p2F9o
参考资料:http://www.cnblogs.com/Kinglee/archive/2009/08/25/1553938.html
http://www.nbcoder.net
Silverlight以列表显示数据库数据_DataGrid的更多相关文章
- 读取数据库数据,并将数据整合成3D饼图在jsp中显示
首先我将生成饼图的方法独立写成一个PieChar.java类,详细代码如下:(数据库需要自己建,如有需要的话) import java.io.IOException; import java.sql. ...
- DBImport v3.44 中文版发布:数据库数据互导及文档生成工具(IT人员必备)
前言: 距离上一个版本V3.3版本的文章发布,已经是1年10个月前的事了. 其实版本一直在更新,但也没什么大的功能更新,总体比较稳定,所以也不怎么写文介绍了. 至于工作上的事,之前有半年时间跑去学英语 ...
- MySQL数据库数据存放位置修改
MySQL数据库数据存放位置修改 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品.MySQL 最流行的关系型数据库管理系统,在 WEB 应用方 ...
- 在Linux环境下,将Solr部署到tomcat7中,导入Mysql数据库数据, 定时更新索引
什么是solr solr是基于Lucene的全文搜索服务器,对Lucene进行了扩展优化. 准备工作 首先,去下载以下软件包: JDK8:jdk-8u60-linux-x64.tar.gz TOMCA ...
- php实现数据库数据读取生成缓存文件
有些时候我们希望减少对数据库的 查询来提高程序的性能,因为这些数据不是经常变更的,而是会在很长一段时间内都不会变化,因此,我们每连接一次数据库,都会把相应的结果用文件的形式保存 起来.比如对于一个商城 ...
- jxl读数据库数据生成xls 并下载
1.所需jar jxl-2.6.10.jar jxls-core-1.0-RC-3.jar jxls-reader-1.0-RC-3.jar 2. excel修改行宽度封装 SheetColumn.j ...
- 效率最高的Excel数据导入---(c#调用SSIS Package将数据库数据导入到Excel文件中【附源代码下载】) 转
效率最高的Excel数据导入---(c#调用SSIS Package将数据库数据导入到Excel文件中[附源代码下载]) 本文目录: (一)背景 (二)数据库数据导入到Excel的方法比较 ...
- mysql load data infile的使用 和 SELECT into outfile备份数据库数据
LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name.txt' [REPLACE | IGNORE] INTO TABLE t ...
- atitit.数据验证--db数据库数据验证约束
atitit.数据验证--db数据库数据验证约束 1. 为了加强账户数据金额的安全性,需要增加验证字段..1 2. 创建帐户1 3. 更改账户2 4. ---code3 5. --fini4 1. 为 ...
随机推荐
- Ubuntu 安装 ImageMagic(6.9.1-6)及 PHP 的 imagick (3.0.1)扩展
关于 ImageMagic 和 imagick 的介绍,见<图片处理神器ImageMagick以及PHP的imagick扩展> 和 <Ubuntu下安装ImageMagick和Mag ...
- UItableview里面的header、footer
#import "ViewController.h" #import "MJRefresh.h" @interface ViewController () { ...
- HTML Questions:Front-end Developer Interview Questions
What's a doctype do? Instruct the browser to render the page. What's the difference between standard ...
- LR网页细分图中的时间详解
Web Page Diagnostics: 1)DNS Resolution:浏览器访问一个网站的时候,一般用的是域名,需要dns服务器把这个域名解析为IP,这个过程就是域名解析时间,如果我们在局域网 ...
- Memcache技术分享:介绍、使用、存储、算法、优化、命中率
1.memcached 介绍 1.1 memcached 是什么? memcached 是以LiveJournal旗下Danga Interactive 公司的Brad Fitzpatric 为首开发 ...
- SELECT 'www' = 0; 1
http://dev.mysql.com/doc/refman/5.7/en/type-conversion.html MySQL 5.7 Reference Manual / Functions ...
- 关于Java中File的renameTo函数
先看Java编程实战经典中的一道习题: 编写程序,程序运行时输入目录名称,并把该目录下的所有文件名后缀修改成.txt. 按照题意,我在d盘新建了文件夹test,并在该文件夹下新建了一个文件file.d ...
- Listener-监听器+ServletContext+ApplicationContext
参考资料 ServletContext和ApplicationContext有什么区别 ServletContext:是web容器的东西, 一个webapp一个, 比session作用范围要大, 从中 ...
- 【php学习】时间函数
手工画了一张图,来大体概括php中对于时间的处理函数 首先时间戳是这样“1441202665”的一串数字,虽然人看起来麻烦,但是计算机却很容易识别这样的时间表示形式. 所以给计算机看的时间是时间戳,给 ...
- (转)CAS (4) —— CAS浏览器SSO访问顺序图详解(CAS Web Flow Diagram by Example)
CAS (4) —— CAS浏览器SSO访问顺序图详解(CAS Web Flow Diagram by Example) tomcat版本: tomcat-8.0.29 jdk版本: jdk1.8.0 ...