Blue Theme Orange Theme Green Theme Red Theme
 
Nevron Gauge for SharePoint
Home | Forums | Videos | Photos | Blogs | Beginners | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
6 Months Free & No Setup Fees ASP.NET Hosting!
Search :       Advanced Search »
Home » Silverlight » Silverlight RIA Service using ADO.NET Entity Data Model: Part II

Silverlight RIA Service using ADO.NET Entity Data Model: Part II

This article demonstrates how to use RIA services with ADO.NET Entity Data Model and how to use page navigation in Silverlight.

Author Rank :
Page Views : 1921
Downloads : 19
Rating :
 Rate it
Level : Intermediate
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
RIAExample.zip
 
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


This article demonstrates how to use RIA services with ADO.NET Entity Data Model and how to use page navigation in Silverlight.

First of all as usual make a new Silverlight project and put name of project and location. By default is creates 2 project like this.

image1.gif

Image1.

There are two projects created there one is works as client and another one web project works as server.

Now add data model in web project and configure it to database.

image2.gif

Image2.

image3.gif

Image3

Click Next.

image4.gif

Image4.

Click Next. And choose database objects and click finish.

image5.gif

Image5

Now let's start working on client project.

First of all we have to fetch data on a grid. So declare some namespace on page.

xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"
xmlns:dataform="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
xmlns:my1="clr-namespace:RIAExample.Web.Services"
xmlns:my2="clr-namespace:RIAExample.Controls"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"

here is DomainDataSurce

<riaControls:DomainDataSourceAutoLoad="True" d:DesignData="{d:DesignInstancemy:Customer,CreateList=true}"Height="0"LoadedData="customerDomainDataSource_LoadedData" Name="customerDomainDataSource"LoadSize="10"QueryName="GetCustomersQuery" Width="0">

<
riaControls:DomainDataSource.DomainContext>
<
my1:CustomerDomainContext />
</
riaControls:DomainDataSource.DomainContext>

Filtering based on customer id with text box value

<riaControls:DomainDataSource.FilterDescriptors>
      <
riaControls:FilterDescriptor
      PropertyPath="CustomerID"
      Operator="StartsWith" Value="{BindingElementName=customerIDText, Path=Text}">
      </riaControls:FilterDescriptor>
</
riaControls:DomainDataSource.FilterDescriptors>

<riaControls:DomainDataSource.GroupDescriptors>
      <
riaControls:GroupDescriptorPropertyPath="CustomerID" />
</riaControls:DomainDataSource.GroupDescriptors>--></riaControls:DomainDataSource>

DataGrid part

<my2:BusyIndicator x:Name="busyIndicator1" Width="400"IsBusy="{BindingElementName=customerDomainDataSource, Path=DomainContext.IsLoading}" />

<sdk:DataGridAutoGenerateColumns="False"ItemsSource="{BindingElementName=customerDomainDataSource, Path=Data}"
Name="customerDataGrid"RowDetailsVisibilityMode="VisibleWhenSelected"MinHeight="250"
Height="Auto">
      <sdk:DataGrid.Columns>
            <
sdk:DataGridTemplateColumn Header="Customer ID">
                  <sdk:DataGridTemplateColumn.CellTemplate>
                        <
DataTemplate>
                              <
HyperlinkButton x:Name="CustomerIDHyperlink" Content="{Binding Path=CustomerID, Mode=OneWay}" Click="EditHyperlink_Click"></HyperlinkButton>
                        </DataTemplate>
                  </
sdk:DataGridTemplateColumn.CellTemplate>
            </
sdk:DataGridTemplateColumn>
            <
sdk:DataGridTextColumn x:Name="companyNameColumn" Binding="{Binding Path=CompanyName}" Header="Company Name" Width="SizeToHeader" />
            <sdk:DataGridTextColumn x:Name="contactNameColumn" Binding="{Binding Path=ContactName}" Header="Contact Name" Width="SizeToHeader" />
            <sdk:DataGridTextColumn x:Name="contactTitleColumn" Binding="{Binding Path=ContactTitle}" Header="Contact Title" Width="SizeToHeader" />
            <sdk:DataGridTextColumn x:Name="countryColumn" Binding="{Binding Path=Country}" Header="Country" Width="SizeToHeader" />
            <sdk:DataGridTextColumn x:Name="postalCodeColumn" Binding="{Binding Path=PostalCode}" Header="Postal Code" Width="SizeToHeader" />
      </sdk:DataGrid.Columns>
      </
sdk:DataGrid>
      <sdk:DataPager Height="26"HorizontalAlignment="right" Name="dataPager1"PageSize="10"VerticalAlignment="Top" Width="Auto" Source="{BindingElementName=customerDomainDataSource, Path=Data}" />

DataForm

<dataform:DataForm x:Name="dataForm1" Header="Customer Information"AutoGenerateFields="False"AutoEdit="False"AutoCommit="False"CurrentItem="{BindingSelectedItem,ElementName=customerDataGrid}" Margin="0,12,0,0"DeletingItem="dataForm1_DeletingItem">
      <dataform:DataForm.EditTemplate>
            <
DataTemplate>
                  <
StackPanel>
                        <
dataform:DataField Label="Customer ID">
                              <TextBoxIsReadOnly
                              Text="{BindingCustomerID, Mode=OneWay}" />
                        </dataform:DataField>
                        <
dataform:DataField Label="Company Name">
                              <TextBox Text="{BindingCompanyName, Mode=TwoWay}" />
                        </dataform:DataField>
                        <
dataform:DataField Label="Contact Name">
                              <TextBox Text="{BindingContactName, Mode=TwoWay}" />
                        </dataform:DataField>
                        <
dataform:DataField Label="Contact Title">
                              <TextBox Text="{BindingContactTitle, Mode=TwoWay}" />
                        </dataform:DataField>
                        <
dataform:DataField Label="Country">
                              <TextBox Text="{Binding Country, Mode=TwoWay,NotifyOnValidationError=True,ValidatesOnExceptions=True }" />
                        </dataform:DataField>
                        <
dataform:DataField Label="PostalCode">
                              <TextBox Text="{BindingPostalCode, Mode=TwoWay,NotifyOnValidationError=True,ValidatesOnExceptions=True }" />
                        </dataform:DataField>
                  </
StackPanel>
            </
DataTemplate>
      </
dataform:DataForm.EditTemplate>
</
dataform:DataForm>
<
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>

Now run the application, result should be like this.

image6.gif
Image6.

Now if you enter some text in text box then result should be filter automatically.

image7.gif
Image7.

Now if you click on customer id and you want sent that id t another page then u have to write code like this.

<sdk:DataGridTemplateColumn Header="Customer ID">
      <sdk:DataGridTemplateColumn.CellTemplate>
            <
DataTemplate>
                  <
HyperlinkButton x:Name="CustomerIDHyperlink" Content="{Binding Path=CustomerID, Mode=OneWay}" Click="EditHyperlink_Click"></HyperlinkButton>
            </DataTemplate>
      </
sdk:DataGridTemplateColumn.CellTemplate>
</
sdk:DataGridTemplateColumn>

private void EditHyperlink_Click(object sender, System.Windows.RoutedEventArgs e)
{
Customer currentEvent = customerDataGrid.SelectedItemasCustomer;
if (currentEvent != null)
{
NavigateToEditEvent(currentEvent.CustomerID);
}
}

private void NavigateToEditEvent(stringeventId)
{
NavigationService.Navigate(newUri("/Detail?CustomerID=" +
eventId, UriKind.Relative));
}


Detail page should be like this.

image8.gif


Image8.

Hope this will help. If you have any questions then download attached project or drop me a comment in www.c-sharcorner.com  comment section.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Raj Kumar

Raj Kumar is a Microsoft MVP and Senior Software Engineer with lots of hands on experience using ASP.NET 2.0/3.5, AJAX, MVC, C#, Visual Basic .NET, SQL Server 2005/2008, Oracle, WPF, WCF, XAML and Silverlight. He has over 6 years of IT experience working most on Microsoft technologies. He holds Master's degree in Computer Science. When he is not writing code, he likes to write articles and play cricket.

Reach him at raj2511984@gmail.com 

 

Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Nevron Gauge for SharePoint
Become a Sponsor
 Comments

 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.