WEB开发网
开发学院图形图像Flash Silverlight(28) - 2.0通信之调用ADO.NET Data Se... 阅读

Silverlight(28) - 2.0通信之调用ADO.NET Data Services(数据服务)

 2009-03-13 11:57:51 来源:WEB开发网   
核心提示: NorthwindDataService.svc.csusing System;using System.Collections.Generic;using System.Data.Services;using System.Linq;using System.ServiceModel.W

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 通信 调用

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接