Observable Collections
page 6 of 9
by frans eilering
Feedback
Average Rating: 
Views (Total / Last 10 Days): 40622/ 46

Mainpage.aspx

In your mainpage.aspx, drag a datagrid to your grid.

Code for mainpage.aspx

<UserControl x:Class="ObservableCollection.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:DesignHeight="300" d:DesignWidth="732" 
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
 
    <Grid x:Name="LayoutRoot" Background="White">
        <sdk:DataGrid 
            AutoGenerateColumns="True" 
            Height="153" 
            HorizontalAlignment="Left" 
            Margin="9,14,0,0" 
            Name="DataGrid1" 
            VerticalAlignment="Top" 
            Width="711" />
    </Grid>
</UserControl>

Change the AutoGenerateColumns to true.

Build your solution again otherwise your servicereference will not be implemented correctly.

The the code behind for your mainpage.aspx. Press F7 to open this code page.

Insert the code below.

Code for Mainpage.aspx.vb

Partial Public Class MainPage
    Inherits UserControl
 
    Public Sub New()
        InitializeComponent()
        Dim proxy As ServiceReference1.Service1Client = New 
ServiceReference1.Service1Client
        AddHandler proxy.FindContactListCompleted, AddressOf GetContactcompleted
        proxy.FindContactListAsync()
  
    End Sub
 
    Sub GetContactcompleted(ByVal sender As Object, ByVal e As 
ServiceReference1.FindContactListCompletedEventArgs)
        DataGrid1.ItemsSource = e.Result
    End Sub
End Class

The config.web may be changed when implementing the service. Make sure the connectionstring is properly inserted in this file.

    <appSettings>
        <add key="ConnectionItalie" value="Data Source='URL'; user 
ID='username';Password='Password';Initial Catalog='DatabaseName';" />
    </appSettings>

This code first creates a proxy variable, a link to our servicereference1.

When you type AddHandler proxy. with a dot, all possibilities will be shown for this proxy.

One of them is FindContactListCompleted. So, as soon as our service got all the information from the database we need to do something with it. What we do is in our GetContactcompleted subroutine. So we add a handler to this FindContactListCompleted.

Then we have to call the service using proxy.FindContactListAsync()

In the subroutine GetContactcompleted we bind the result to our datagrid.

Now run your application. This is the result.


View Entire Article

User Comments

Title: C# Code example   
Name: eilering
Date: 2011-09-16 3:50:25 AM
Comment:
The VB code is very basic. If you copy the code and use a convertor like
http://converter.telerik.com/
then you can paste it and you get the C# code.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-26 2:15:24 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search