This example demonstrates how data in Virtuoso can be updated from a Microsoft .NET RIA Services application. The example is a continuation of the first example in Creating a Simple .Net RIA Services Application to Display Data From Virtuoso.
The EmployeeService Domain Service Class was only used to display data so was created read only. In this example we need to be able to update the data so we need to remove the read only Domain Service Class and create a new on.
We want to create a master detail style page. To do this we will use the DomainDataSourceComponent from the Silverlight Components. But first we will add a pager so only 5 records are displayed at a time.
xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Ria.Controls" xmlns:ds="clr-namespace:DemoApplication.Web"
<riaControls:DomainDataSource x:Name="EmployeeDataSource" QueryName="GetEmployeesQuery" LoadSize="10" AutoLoad="True"> <riaControls:DomainDataSource.DomainContext> <ds:EmployeeService2/> </riaControls:DomainDataSource.DomainContext> </riaControls:DomainDataSource>
public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); } }
<data:DataGrid MinHeight="100" IsReadOnly="True" ItemsSource="{Binding Data, ElementName=EmployeeDataSource}" x:Name="DataGrid1"></data:DataGrid> />
<data:DataPager PageSize="5" Source="{Binding Data, ElementName=employeeDataSource}" Margin="0,-1,0,0"></data:DataPager>
xmlns:dataForm="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
<dataForm:DataForm x:Name="dataForm1" Header="Employee Information" AutoGenerateFields="False" AutoEdit="False" AutoCommit="False" CurrentItem="{Binding SelectedItem, ElementName=DataGrid1}" Margin="0,12,0,0"> <dataForm:DataForm.EditTemplate> <DataTemplate> <StackPanel> <dataForm:DataField Label="Employee ID"> <TextBox Text="{Binding EmployeeID, Mode=TwoWay}" /> </dataForm:DataField> <dataForm:DataField Label="First Name"> <TextBox Text="{Binding FirstName, Mode=TwoWay}" /> </dataForm:DataField> <dataForm:DataField Label="Last Name"> <TextBox Text="{Binding LastName, Mode=TwoWay}" /> </dataForm:DataField> <dataForm:DataField Label="Courtesy Title"> <TextBox Text="{Binding TitleOfCourtesy, Mode=TwoWay}" /> </dataForm:DataField> <dataForm:DataField Label="Hire Date"> <TextBox Text="{Binding HireDate, Mode=TwoWay}" /> </dataForm:DataField> <dataForm:DataField Label="Title"> <TextBox Text="{Binding Title, Mode=TwoWay}" /> </dataForm:DataField> <dataForm:DataField Label="Reports To"> <TextBox Text="{Binding ReportsTo, Mode=TwoWay}" /> </dataForm:DataField> <dataForm:DataField Label="Region"> <TextBox Text="{Binding Region, Mode=TwoWay}" /> </dataForm:DataField> <dataForm:DataField Label="Address"> <TextBox Text="{Binding Address, Mode=TwoWay}" /> </dataForm:DataField> <dataForm:DataField Label="City"> <TextBox Text="{Binding City, Mode=TwoWay}" /> </dataForm:DataField> <dataForm:DataField Label="Country Code"> <TextBox Text="{Binding CountryCode, Mode=TwoWay}" /> </dataForm:DataField> <dataForm:DataField Label="Postal Code"> <TextBox Text="{Binding PostalCode, Mode=TwoWay}" /> </dataForm:DataField> </StackPanel> </DataTemplate> </dataForm:DataForm.EditTemplate> </dataForm:DataForm>
<ScrollViewer BorderThickness="0" VerticalScrollBarVisibility="Auto" Padding="12,0,12,0" Margin="-2"> <StackPanel Margin="0,12,0,12" Orientation="Vertical" > . . . </StackPanel> </ScrollViewer>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,12,0,0"> <Button x:Name="submitButton" Width="75" Height="23" Content="Submit" Margin="4,0,0,0" Click="submitButton_Click"/> </StackPanel>
private void submitButton_Click(object sender, RoutedEventArgs e) { EmployeeDataSource.SubmitChanges(); }