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


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

Code for mainpage.aspx

<UserControl x:Class="ObservableCollection.MainPage"
    d:DesignHeight="300" d:DesignWidth="732" 
    <Grid x:Name="LayoutRoot" Background="White">
            Width="711" />

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()
        Dim proxy As ServiceReference1.Service1Client = New 
        AddHandler proxy.FindContactListCompleted, AddressOf GetContactcompleted
    End Sub
    Sub GetContactcompleted(ByVal sender As Object, ByVal e As 
        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.

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

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
The VB code is very basic. If you copy the code and use a convertor like
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-22 4:43:39 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search