Silverlight(28) - 2.0通信之调用ADO.NET Data Services(数据服务)
2009-03-13 11:57:51 来源:WEB开发网NorthwindDataService.svc.cs
using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
namespace Silverlight20.Web.DataService
{
public class NorthwindDataService : DataService<NorthwindEntities>
{
public static void InitializeService(IDataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.All);
}
}
}
2、Silverlight 调用数据服务
DataService.xaml
<UserControl x:Class="Silverlight20.Communication.DataService"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data">
<StackPanel HorizontalAlignment="Left" Margin="5">
<TextBlock x:Name="lblMsg" Margin="10" Foreground="Red" />
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="lblCategoryName" Text="类别名称" Margin="10" />
<TextBox x:Name="txtCategoryName" Width="100" Margin="10" />
<TextBlock x:Name="lblDescription" Text="类别备注" Margin="10" />
<TextBox x:Name="txtDescription" Width="100" Margin="10" />
<Button x:Name="btnAdd" Content="添加" Margin="10" Click="btnAdd_Click" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button x:Name="btnUpdate" Content="更新选中" Margin="10" Click="btnUpdate_Click" />
<Button x:Name="btnDelete" Content="删除选中" Margin="10" Click="btnDelete_Click" />
</StackPanel>
<data:DataGrid Name="dataGrid1" Margin="10" AutoGenerateColumns="False" ItemsSource="{Binding}"
SelectionChanged="DataGrid_SelectionChanged">
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="类别ID" Binding="{Binding CategoryID}" />
<data:DataGridTextColumn Header="类别名称" Binding="{Binding CategoryName}" />
<data:DataGridTextColumn Header="类别备注" Binding="{Binding Description}" />
</data:DataGrid.Columns>
</data:DataGrid>
<data:DataGrid Name="dataGrid2" Margin="10" AutoGenerateColumns="False" ItemsSource="{Binding}">
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="产品ID" Binding="{Binding ProductID}" />
<data:DataGridTextColumn Header="产品名称" Binding="{Binding ProductName}" />
</data:DataGrid.Columns>
</data:DataGrid>
</StackPanel>
</UserControl>
Tags:Silverlight 通信 调用
编辑录入:爽爽 [复制链接] [打 印]- ››silverlight全屏显示图片
- ››Silverlight MVVM 模式(一) 切近实战
- ››调用已注册会员人数和最新会员名称
- ››Silverlight for Windows Phone 7开发系列(1):...
- ››Silverlight for Windows Phone 7开发系列(2):...
- ››Silverlight for Windows Phone 7开发系列(3):...
- ››Silverlight for Windows Phone 7开发系列(4):...
- ››Silverlight for Symbian
- ››调用android系统自带功能
- ››调用HHA_CompileHHP编译chm工程
- ››调用所有的 android activity 的实现
- ››调用 Android 内置图片的方法
更多精彩
赞助商链接