• Home
  • About
  • Forum
  • News
  • SimplySqlServer.Com && SimplyAspDotNet.Com
  • Sitemap

Join Ours Forum

Asp.Net,C#,Ajax,Sql server,Silverlight,WCF,WPF,NHibernate,Javascript codes exambles articles,Programming exambles.

RSS Feed
  • .NET Matters: Asynchronous HttpWebRequests, Interface Implementation, and More
  • Editor’s Note: New Technologies and a New Magazine
  • .NET Interop: Getting Started With IronRuby And RSpec, Part 1
  • Smart Client: Building Distributed Apps with NHibernate and Rhino Service Bus
  • Editor’s Note: Best Practices
  • New Stuff: Resources for Your Developer Toolbox
  • Data Points: LINQ Projection Queries and Alternatives in WCF Services
  • Concurrent Affairs: Solving The Dining Philosophers Problem With Asynchronous Agents
  • DCOM Interop: Generate Custom Managed C++ Wrappers for Easier COM Interoperation Using DCOMSuds
  • Editor’s Note: I Am The Business
  • Top 10 Articles,


    Silverlight Datagrid Select Update Delete Insert Asp.Net C#

    Differences Similarities Benefits Between Typed Datasets and Untyped Datasets asp.net c#

    Linq to Sql Introduction Entities Ado.Net C# SqlClasses Attributes Linq Mapping

    Linq Programming/How Linq Works?/Linq Implementation In Asp.Net C# Ado.Net

    Performing Developing Using Investigating Asp.Net 2.0 Ajax Application Development Asp.Net C#

    Hosting/Install Wcf Services in a Windows Service Asp.Net C#

    Connecting Silverlight to Wcf Asp.Net C#

    Silverlight Data Grid Data Binding WCF Asp.Net C#

    Invoking/Accessing/Calling WCF Service Without Adding/Creating Proxy/Reference Asp.Net C#

    Performing Doing Creating Insert Update Delete sql data Using Linq Database Asp.Net C#

    Silverlight DataGrid Update Delete Select Insert Using Linq WCF Asp.Net C#

    Posted by on October 23, 2010 Leave a comment (2) Go to comments

    Introduction:
    In this article, i am going to explain how to perform a silverlight datagrid insert update delete functionalities.

    Main:
    Silverlight datagrid is defined in namespace System.Windows.Controls.Data,

    <UserControl xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  x:Class="AspDotNetCodesOnline.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" 
        mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
      <Grid x:Name="LayoutRoot">
            <data:DataGrid x:Name="dgSilverligh" AutoGenerateColumns="false" Width="450" Height="200" RowDetailsVisibilityMode="VisibleWhenSelected" >
                <data:DataGrid.RowDetailsTemplate>
                    <DataTemplate >
                        <TextBlock Text="Row details go here"></TextBlock>
                    </DataTemplate>
                </data:DataGrid.RowDetailsTemplate>
                <data:DataGrid.Columns>
                    <data:DataGridTextColumn    Binding="{Binding Member_id}"    Header="ID" ></data:DataGridTextColumn>
                    <data:DataGridTextColumn Binding="{Binding FirstName}"    Header="First Name" />
                    <data:DataGridTextColumn Binding="{Binding LastName}"    Header="Last Name" />
                    <data:DataGridTextColumn Binding="{Binding Address}"    Header="Address" />
                    <data:DataGridTextColumn Binding="{Binding City}"    Header="City" />
                </data:DataGrid.Columns>
            </data:DataGrid>
      </Grid>
    </UserControl>

    I Used the below 3 contracts,

    Select:

    public List<Emp> GetEmps()
            {
                DataClassesDataContext db = new DataClassesDataContext();
                var members = from member in db.Emps
                              select member;
     
                //return list of member objects
                return members.ToList();
            }
     
     
    Update:
            public bool UpdateEmp(Emp objMem)
            {
                DataClassesDataContext db = new DataClassesDataContext();
                db.Log = new Vandermotten.Diagnostics.DebuggerWriter();
                db.Emps.Attach(objMem, true);
                db.SubmitChanges();
     
                return true;
            }
     
     
    Delete:
            public bool DeleteEmp(Emp objMem)
            {
                DataClassesDataContext db = new DataClassesDataContext();
                var mem = db.Emps.First(m => m.Empid == objMem.Empid);
                db.Emps.DeleteOnSubmit(mem);
                db.SubmitChanges();
                return true;
     
            }

    In Silverlight UserControl Page,

    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 AspDotNetCodesOnline.EmpService;
     
    namespace AspDotNetCodesOnline
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
     
                dgSilverligh.BeginningEdit += new EventHandler<DataGridBeginningEditEventArgs>(dgSilverlight_BeginningEdit);
                dgSilverligh.RowEditEnded += new EventHandler<DataGridRowEditEndedEventArgs>(dgSilverlight_RowEditEnded);
                this.KeyDown += new KeyEventHandler(OnKeyDown);
     
                BindToGrid();
            }
     
            void OnKeyDown(object sender, KeyEventArgs e)
            {
     
                if (e.Key == Key.Delete && dgSilverligh.SelectedItem != null)
                {
                    EmpService.Emp objEmp = dgSilverligh.SelectedItem as EmpService.Emp;
     
                    EmpService.DataServiceClient  webService = new EmpService.DataServiceClient();
                    webService.DeleteEmpCompleted  += new EventHandler<DeleteEmpCompletedEventArgs>(DeleteEmpCompleted);
     
     
                    webService.DeleteEmpAsync(objEmp);
     
                }
     
            }
     
            //This method will be called when GetEmps asynchronous call will be completed
            protected void DeleteEmpCompleted(object sender, DeleteEmpCompletedEventArgs  e)
            {
                bool flag = Convert.ToBoolean(e.Result);
                if (flag)
                {
                    //delete success;
                    //refresh datagrid
                    BindToGrid();
                }
     
            }
     
     
            private void BindToGrid()
            {
                DataServiceClient webService = new DataServiceClient();
                webService.GetEmpsCompleted += new EventHandler<GetEmpsCompletedEventArgs>(GetEmpsCompleted);
     
                //Now make asynchronous call
                webService.GetEmpsAsync();
            }
     
            //This method will be called when GetEmps asynchronous call will be completed
            protected void GetEmpsCompleted(object sender, GetEmpsCompletedEventArgs e)
            {
                //Bind result to Silverlight Datagrid
                dgSilverligh.ItemsSource = e.Result;
            }
     
     
            void dgSilverlight_RowEditEnded(object sender, DataGridRowEditEndedEventArgs e)
            {
                //Row has been updated. Call WCF Service to update into database
                EmpService.Emp objEmp = e.Row.DataContext as EmpService.Emp;
     
                EmpService.DataServiceClient webService = new DataServiceClient();
                webService.UpdateEmpCompleted += new EventHandler<UpdateEmpCompletedEventArgs>(UpdateEmpCompleted);
     
                webService.UpdateEmpAsync(objEmp);
            }
     
            protected void UpdateEmpCompleted(object sender, UpdateEmpCompletedEventArgs e)
            {
                bool result = Convert.ToBoolean(e.Result);
     
                if (result)
                {
                    //Update Success;
                }
     
            }
     
            void dgSilverlight_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
            {
                //Beginning of row editing 
                //Don't need this event in our sample code
            }
     
     
     
        }
     
        public class Emp
        {
            public Emp(int Emp_id, string firstName, string lastName, string address, string city)
            {
                this.FirstName = firstName;
                this.LastName = lastName;
                this.Emp_id = Emp_id;
                this.City = city;
                this.Address = address;
            }
            public int Emp_id
            {
                get;
                set;
            }
            public string FirstName
            {
                get;
                set;
            }
            public string LastName
            {
                get;
                set;
            }
     
            public string Address
            {
                get;
                set;
            }
     
            public string City
            {
                get;
                set;
            }
     
        }
    }

    Conclusion:
    Hope this helps,
    Happy coding.

    Asp.Net
    ← Creating Developing WCF Silverlight Chat Application Xaml C# Wpf
    Using Accessing UpdatePanel Control works Advantages Disadvantages Asp.Net C# →

    Learn Easily Using Video Tutorials


    How to choose the right Java IDE – explained Eclipse NetBeans BlueJ

    Developing/Creating/Performing/Configuring Java Applications Using Eclipse IDE

    Step By Step Guide for Download/Install Configure Eclipse IDE for Java

    Editing data with the GridView control Asp.Net C#

    Registering/Configuring Web Controls globally in web.config file asp.net c#

    Registering/Configuring Web Controls globally in web.config file asp.net c#

    Best way to prepare asp.net Interview - Success Stories

    Download Important Questions and PPT's:

    Sql Server Important Questions Online free download

    Dotnet Important Questions Online free download

    Exploring Linq to Sql Process Flow

    Learn how to perform silverlight programming

    Learn OOPs concepts in better and well manner

    Learn Ajax in better and well manner

    Leave a comment

    2 Comments.

    1. grants for women November 16, 2010 at 6:39 pm

      nice post. thanks.

      Reply

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    *

    *


    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    Trackbacks and Pingbacks:

    • Silverlight DataGrid Update Delete Select Insert Using Linq WCF Asp.Net C# - Pingback on 2010/10/23/ 14:54

    Enter your email address:

    Delivered by FeedBurner

    • Recent Posts

      • .NET Matters: Asynchronous HttpWebRequests, Interface Implementation, and More
      • Editor’s Note: New Technologies and a New Magazine
      • .NET Interop: Getting Started With IronRuby And RSpec, Part 1
      • Smart Client: Building Distributed Apps with NHibernate and Rhino Service Bus
      • Editor’s Note: Best Practices
    • Search by Tags!

      Advanced application applications architecture ASPNET Basic Basics Bracket Briefs Build building control controls create Custom Cutting developer Drive Editors Entity Forms Foundations Framework Guide inside JavaScript Method Microsoft Points Resources Security Server service Services Silverlight Started Studio Stuff system testing Toolbox Tutorial Using Visual windows
    • Archives

      • October 2011
      • September 2011
      • August 2011
      • July 2011
      • June 2011
      • May 2011
      • April 2011
      • March 2011
      • February 2011
      • January 2011
      • December 2010
      • November 2010
      • October 2010
      • September 2010
      • July 2010
      • June 2010
      • May 2010
      • April 2010
      • March 2010
      • February 2010
      • January 2010
      • December 2009
      • April 2009
      • February 2008
      • October 2007
      • August 2007
      • July 2007
      • June 2007

    Copyright © 2012 aspdotnetcodesonline.com

    Δ Top
    Social Buttons by Linksku