How To: Creating Tooltips in Silverlight 2#

Tooltips are great additions to any interface and in this article I'm going to show you how to attach a tooltip to control in Silverlight 2.

To start, let's assume that we have a button that we want to add a tooltip to:

[XAML]

<UserControl x:Class="KeithRull.Silverlight.CreatingTooltips.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="#FF1E238E">
        <Button Content="Hover over me!" 
                Height="20" 
                Width="100" Margin="30 40" 
                VerticalAlignment="Top" 
                HorizontalAlignment="Left">
                
        </Button>
    </Grid>
</UserControl>

[Rendered UI]

In order or us to attach a tooltip to our button we need to create a reference to the TooltipService.Tooltip inside the our button's XAML declaration. We also need to setup the Tooltip.Content to tell the compiler what to show when the user hover's to our button.

[XAML]

<UserControl x:Class="KeithRull.Silverlight.CreatingTooltips.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="#FF1E238E">
        <Button Content="Hover over me!" 
                Height="20" 
                Width="100" Margin="30 40" 
                VerticalAlignment="Top" 
                HorizontalAlignment="Left">
            <ToolTipService.ToolTip>
                <ToolTip>
                    <ToolTip.Content>
                        <TextBlock TextWrapping="Wrap">
                            Hooray! I'm alive!.
                        </TextBlock>
                    </ToolTip.Content>
                </ToolTip>
            </ToolTipService.ToolTip>
        </Button>
    </Grid>
</UserControl>

[Rendered UI (at runtime)]

The message "Hooray! I'm alive!" appeared when the user hovers over our button. We can also cutomize how our tooltip appears by adding more XAML elements in the Tooltip.Content property.

[XAML]

<UserControl x:Class="KeithRull.Silverlight.CreatingTooltips.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="#FF1E238E">
        <Button Content="Hover over me!" 
                Height="20" 
                Width="100" Margin="30 40" 
                VerticalAlignment="Top" 
                HorizontalAlignment="Left">
            <ToolTipService.ToolTip>
                <ToolTip Background="#FFFFFF" Width="150">
                    <ToolTip.Content>
                        <StackPanel>
                            <Image Source="images/silverlight.png" />
                            <TextBlock HorizontalAlignment="Right">
                                It rocks like a champ!
                            </TextBlock>
                        </StackPanel>    
                    </ToolTip.Content>
                </ToolTip>
            </ToolTipService.ToolTip>
        </Button>
    </Grid>
</UserControl>

[Rendered UI (at runtime)]

Another customization that you might want to do is specifying the HorizontalOffset and the VerticalOffset. This allows you to specify where the tooltip will appear in reference to your target control.

Monday, March 09, 2009 10:49:38 PM (GMT Standard Time, UTC+00:00) #    Comments [0]  | 

 

ASP.NET MVC RC 2 Source code and Futures are now available on CodePlex#

I just saw this twitter...

Sweeeeet!

Time to start polishing my ASP.NET MVC skills. I've played with ASP.NET MVC before but never had the chance to use it other than building small samples. I might be rusty but I know I'll have a great companion book in learning ASP.NET MVC 1.0 once Rob, Scott, Scott and Phil's upcoming book comes out.

Wednesday, March 04, 2009 1:00:26 AM (GMT Standard Time, UTC+00:00) #    Comments [0]  | 

 

How To: Blocking\Restricting certain file types from being saved to a directory using FileSystemWatcher#

A user a devpinoy.org posted a question on the forum section asking if there's a way to restrict files from being saved in a directory. I know you can do this via the FileSystemWatcher class so I quickly whipped my Visual Studio 2008 IDE and started building a prototype application to demonstrate the solution.

The first thing that you need to do is to set-up some key details on what we want to watch/monitor

private const string ALLOWED_FILE_EXTENSION = ".doc";
private const string DEFAULT_WATCH_FOLDER = @"E:\Test Folder\";

Next, the FileSystemWatcher specify what directory you want to monitor.

FileSystemWatcher watcher = new FileSystemWatcher(DEFAULT_WATCH_FOLDER);

After that you need to setup the notification filters on what type of filesystem changes you want to watch;

watcher.NotifyFilter = NotifyFilters.LastAccess |
                                    NotifyFilters.LastWrite |
                                    NotifyFilters.FileName |
                                    NotifyFilters.DirectoryName |
                                    NotifyFilters.CreationTime;

And finally, we need to set-up the FileSystem events you want our FileSystem. In this case, we only want to monitor Created and Renamed events.

watcher.Created += new FileSystemEventHandler(watcher_Created);
watcher.Renamed += new RenamedEventHandler(watcher_Renamed);

Now, let's start coding our event handlers.

For our event handler, I decided to use one method that would handle both the Created and Rename event. Ideally you want to seperate this to into two different methods because you might want to handle the tow events differently but since all I want to do is to block files\folders that doesn't match my criteria i decided to handle them both using a single method called FileSystemHandler.

void watcher_Renamed(object sender, RenamedEventArgs e)
{
    FileSystemHandler(e.Name, e.FullPath);
}

void watcher_Created(object sender, FileSystemEventArgs e)
{
    FileSystemHandler(e.Name, e.FullPath);    
}

Below is the implementation detail for our FileSystemHandler method.

void FileSystemHandler(string name, string fullpath)
{
    try
    {
        //read the contents of our directory
        DirectoryInfo di = new DirectoryInfo(DEFAULT_WATCH_FOLDER);
        //get the filesysteminfo[] objects
        FileSystemInfo[] fileSystemInfoArray = di.GetFileSystemInfos();

        //there's always going to be one object matching this criteria all the time
        FileSystemInfo found = fileSystemInfoArray.Single(f => f.FullName.Equals(fullpath));

        //if it finds something
        if (found != null)
        {
            //cast the found object to directoryinfo
            DirectoryInfo d = found as DirectoryInfo;

            //if it's null it means it's a FileInfo object
            if (d == null)
            {
                //cast found to a fileinfo object
                FileInfo f = found as FileInfo;

                //delete the file if the extension doesn't match our desired/allowed extension
                if (!f.Extension.Equals(ALLOWED_FILE_EXTENSION))
                {
                    f.Delete();
                }
            }
            else
            {
                //directories are not allowed on this folder too!
                d.Delete(true);
            }
        }
    }
    catch
    {
        //let it sleep for 30 seconds
        Thread.Sleep(30000);

        //it failed so we need to try again recussively
        /*
            note: it's a good idea to set a retry limit here because if we don't 
            then the app will retry to infinity but i'll leave that up to you.
         */
        FileSystemHandler(name, fullpath);
    }
}

What the function above is doing is that it checks to see if the filesystem object that was created on the directory is either a file or a directory. If it is a directory, automatically delete it since we dont want any directory to be saved on our folder. If it is a file we need to check if it's extension matches the allowed file extension. If it matches the allowed extension we let it thru. If it doesn't we call the the Delete method on the FileInfo object to delete the file.

All we need to do now is to tell the watcher to start monitor our folder

watcher.EnableRaisingEvents = true;

Setting EnableRaisingEvents to true triggers our watcher to start monitoring the folder. Setting it to false will stop the watcher.

And we are done! Now we have an application that blocks saving or renaming of files in a folder that doesn't match the allowed file extension.

Below is the full listing of the code for the demo project I built for this article:

using System;
using System.Linq;
using System.Windows.Forms;
using System.IO;
using System.Threading;

namespace KeithRull.FolderSpy
{
    public partial class MainForm : Form
    {
        private bool IsCurrentlyWatching = false;
        private const string ALLOWED_FILE_EXTENSION = ".doc";
        private const string DEFAULT_WATCH_FOLDER = @"E:\Test Folder\";
        FileSystemWatcher watcher;

        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            SetUpWatcher();
        }

        private void watchButton_Click(object sender, EventArgs e)
        {
            if (!IsCurrentlyWatching)
            {
                watchButton.Text = "Stop watching";
                IsCurrentlyWatching = true;

                //start the watcher
                watcher.EnableRaisingEvents = true;
            }
            else
            {
                watchButton.Text = "Start watching";
                IsCurrentlyWatching = false;

                //stop the watcher
                watcher.EnableRaisingEvents = false;
            }
        }

        void watcher_Renamed(object sender, RenamedEventArgs e)
        {
            FileSystemHandler(e.Name, e.FullPath);
        }

        void watcher_Created(object sender, FileSystemEventArgs e)
        {
            FileSystemHandler(e.Name, e.FullPath);    
        }

        void FileSystemHandler(string name, string fullpath)
        {
            try
            {
                //read the contents of our directory
                DirectoryInfo di = new DirectoryInfo(DEFAULT_WATCH_FOLDER);
                //get the filesysteminfo[] objects
                FileSystemInfo[] fileSystemInfoArray = di.GetFileSystemInfos();

                //there's always going to be one object matching this criteria all the time
                FileSystemInfo found = fileSystemInfoArray.Single(f => f.FullName.Equals(fullpath));

                //if it finds something
                if (found != null)
                {
                    //cast the found object to directoryinfo
                    DirectoryInfo d = found as DirectoryInfo;

                    //if it's null it means it's a FileInfo object
                    if (d == null)
                    {
                        //cast found to a fileinfo object
                        FileInfo f = found as FileInfo;

                        //delete the file if the extension doesn't match our desired/allowed extension
                        if (!f.Extension.Equals(ALLOWED_FILE_EXTENSION))
                        {
                            f.Delete();
                        }
                    }
                    else
                    {
                        //directories are not allowed on this folder too!
                        d.Delete(true);
                    }
                }
            }
            catch
            {
                //let it sleep for 30 seconds
                Thread.Sleep(30000);

                //it failed so we need to try again recussively
                /*
                    note: it's a good idea to set a retry limit here because if we don't 
                    then the app will retry to infinity but i'll leave that up to you.
                 */
                FileSystemHandler(name, fullpath);
            }
        }

        void SetUpWatcher()
        {
            watcher = new FileSystemWatcher(DEFAULT_WATCH_FOLDER);
            watcher.NotifyFilter = NotifyFilters.LastAccess |
                                    NotifyFilters.LastWrite |
                                    NotifyFilters.FileName |
                                    NotifyFilters.DirectoryName |
                                    NotifyFilters.CreationTime;
            watcher.Created += new FileSystemEventHandler(watcher_Created);
            watcher.Renamed += new RenamedEventHandler(watcher_Renamed);

        }
    }
}

As always, you can download the code for the complete project here: KeithRull.FolderSpy.zip (40.38 KB)

Wednesday, February 25, 2009 7:48:40 PM (GMT Standard Time, UTC+00:00) #    Comments [0]  | 

 

With great joy we introduce...#

Tuesday, February 24, 2009 5:44:09 PM (GMT Standard Time, UTC+00:00) #    Comments [3]  | 

 

My MIX09 10K Contest Entry: Silverlight Pregnancy Calendar#

I had some free time during the holidays and saw at the MIX09 website that they have a contest entitled MIX09 10K Challenge where they ask participant to create a web application that is either using Microsoft® Silverlight™ or Windows Presentation Foundation, as a XAML Browser Application running in Partial Trust or as a ClickOnce application in 10 kilobytes or less. I decided to take a stab at it and this is what I've comed up with

SilverCalendar: A Silverlight Pregancy Calendar

You can see the app live here http://2009.visitmix.com/MIXtify/TenKDisplay.aspx?SubmissionID=0051

Dont forget to vote when you're there :P LOL

My primary motivation when I built the app is the idea of having something that is going to be useful and at the same time fun to build. My wife is currently 34 weeks pregnant and it made me think that a pregnancy calendar would be q great application to do since it relates to me and my current day to day life. I love pregnancy calendars because it gives you a good daily insight on the progress of your baby and what you might expected as you go along in your daily life as a soon to be parent. 

The application that i built is using Microsoft Silverlight 2 with a backend WCF web service. You can find the pregnancy calendar web service here. I wasn't able to add any animations to the application because I decided to concentrate in adding functionality to app rather than the eye candy' With that said, I'll be posting the non-10K application this week.

Be sure to comeback on this blog in the coming weeks because I'll be publishing the source code to both project soon together with a 11 part tutorial and screencast walkthrough that i have prepared to show how to to build an application using .NET 3.5, WCF, WPF and Silverlight.

Thursday, January 08, 2009 7:47:35 PM (GMT Standard Time, UTC+00:00) #    Comments [0]  | 

 

A Thanksgiving Announcement#

I've been keeping this for months now because I wanted to announce it at this years Thanksgiving... :) 

On June 7, 2008 we learned about this wonderful news:

Yup, I'm going to be a father soon! :) My wife and I are very excited about this blessing to our family. We can't wait to see our baby on February 2009.

Below is the first picture of our baby taken at 6 weeks:

Next is our babys picture at 20 weeks:

I don't have her new picture scanned yet but I'll post it a soon as I have them.4 weeks ago we learned that we are having a baby girl. Sweet! 

As with all first time dads, there's a lot of things to learn. I'm learning a bunch of new stuff everyday and I highly recommend going BabyCenter.com. BabyCenter.com is a site dedicated to babies and parenting in general. They have a ton on articles about babies, pregnancy and parenting which i really love. I go there everyday to check out articles and information that will help me become a great dad. Also, JustMommies.com is a great site too. They have this calendar thingy where you can check out the progress of your baby day-by-day which is pretty cool!

This is what me and my wife are thankful for this Thanksgiving!

Happy Thanksgiving everyone! God Bless!

Family | Life | My Faith
Wednesday, November 26, 2008 11:44:21 PM (GMT Standard Time, UTC+00:00) #    Comments [4]  | 

 

I am a big fan of Tim Tebow..#

and now I respect him even more...

http://sports.espn.go.com/broadband/video/video?id=3569702

I just wish more and more athletes can be like this guy. A lot of the athletes nowadays are either drunkards, gamblers or womanizers which is pretty sad considering that a lot of kids in this generation look up to sport professionals as their role model. 

Tim Tebow is different. He keeps himself grounded and models the message of his faith to people around him which makes him a step above and beyond among his peers.

Thanks and God Bless Tim for being a model to this generation!

Tuesday, November 18, 2008 11:49:38 PM (GMT Standard Time, UTC+00:00) #    Comments [1]  | 

 

Free Coding Assistance Add-in for Visual Studio 2008 from DevExpress#

I just love the guys from DevExpress!

First, they gave away a free version of Refactor! for VB.NET, ASP.NET and C++. Next, they gave away their .NET components for FREE and I mean really FREE! And now they are treating us with CodeRush Xpress!

"CodeRush Xpress is freely available to all Visual Studio 2008 developers and offers a comprehensive suite of tools that enable you and your team to simplify and shape complex code - making it easier to read and less costly to maintain."

I've been using CodeRush + Refactor Pro! for 3+ years now and I could say that it is great productivity tool for any .NET developer. I just love it! It's one of those things that would get you hooked to it wit your first Ctrl+~.

To prove my point that this is great, look at what happened to Jeff's IDE after installing CodeRush and Refactor!

Seriously, It really makes coding that fun when you have CodeRush and Refactor Pro installed (I'm not saying you can play a game inside your IDE, but you got the point right?).

CodeRush Xpress installs a subset of the functionality that you can find with CodeRush and Refactor Pro! but it's worth the download considering the amount of productivity you will gain from these set of functionalities:

CodeRush Xpress includes the following features.

  • Duplicate Line
  • Highlight All References
  • Increase or Reduce Selection
  • Smart Clipboard Operations
  • Generate from Using (TDD)
  • Quick Navigation Window
  • Quick File Navigation

Additionally CodeRush XPress includes this refactorings

  • Add Block Delimiters 
  • Combine Conditionals
  • Compress to Lambda Expression
  • Compress to Ternary Expression
  • Convert to Auto-implemented Property
  • Convert to Initializer
  • Create Backing Store
  • Decompose Initializer
  • Decompose Parameter
  • Expand Lambda Expression
  • Expand Ternary Expression 
  • Extract Method
  • Flatten Conditional
  • Inline Delegate
  • Inline Temp
  • Introduce Local
  • Make Explicit
  • Make Implicit
  • Move Type to File
  • Name Anonymous Method
  • Name Anonymous Type
  • Reverse Conditional
  • Split Conditional
  • Use String.Format
  • Use StringBuilder

What are you waiting for? Go ahead and download CodeRushX! I promise you, you wont regret it!

Friday, November 07, 2008 5:50:45 PM (GMT Standard Time, UTC+00:00) #    Comments [0]  | 

 

KeithRull.NBible: A WPF Bible Application#

A week ago, I started a contest at DevPinoy.org about writing a Bible application and a few people have asked me if I tried my own challenge. I actually did took the challenge and built my own Bible application. I wasn't able to post it as soon as I wanted to do it due to time constrainst. What I built is a WPF Bible application but still needs some polishing to truely call it a "WPF app". 

Now let's begin the tour of the WPF app that I built.

The screen below shows the main interface for the program. The first tab is the browsing tab that allows the user to select a Book and a Chapter they want and displays the contents of your selection on the list below the Comboxes

The bold letters on the upper right side of the list tells you what book and chapter you are currently reading

The second tab is the search tab. This tab has a textbox that allows you to enter your search parameters

It allows you to search by keyword\s

By book and chapter

or by specifying the Book, Chapter and Verse

There are a few more things that I wanted to add this app but wasn't able to do so like building a TreeView similar to CryptoKnight's implementation that allows you to see the Document Map and also a matching word highlighting on the search screen would be a great addition too. Another thing that could be improve is refactoring the code and making the service layer a little bit more generic. I wanted to refactor it a bit more after I finished it but never had a chance to do so. I'll leave it as is for now and hope to update it in the future.

There's a lot more improvements I could think of but I'll leave it for you guys to check and comment on what I could do with this app to improve it. Maybe we could make it an OpenSource application someday.

Anyhow, you can get the source code for this project here. KeithRull.NBible.zip (1.84 MB)

Thanks to everyone who tried the challenge. I promise to do more of these type of contest in the future. 

Again, Thank you, God Bless and Mabuhay ka Filipino Developer!

Thursday, October 30, 2008 11:35:52 PM (GMT Standard Time, UTC+00:00) #    Comments [0]  | 

 

How To: Make A Master-Detail View In ASP.NET#

In part 3 of this 5 part series I am going to show you how to make a Master-Detail View in ASP.NET. I you weren't able to see the two previous post you can check them out here:

This post is a continuation of what we started in the two previous post wherein i show you how to consume a webservice ins ASP.NET and present the values returned by the service to the user in a much more meaninful way.

To start off with this post lets look at how the application from our last article look-liked:

As you can see, we have a textbox that accepts a user-input asking for the symbol to lookup in our webservice, a button that triggers that query event and a DetailsView that displays the returned resultset. This works great.

But what if I have a list of symbols that I want the user to see information regarding them? The answer is to show them in a master-detail view so that the user can get a clearer view of the information on each symbol.

To start with this demo lets begin by deleting everything that we have on the page. Yup! we are starting from scratch so that we can get a clearer picture on how we can build a master-detail view screen. Once everything is cleared on the page let's begin by adding a DataList control on our page with a Label control inside its ItemTemplate:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Keith Rull's Consuming Web Services Sample</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:DataList   ID="stockDataList" 
                            runat="server">
                <ItemTemplate>
                    <asp:Label  ID="quoteLabel" 
                                runat="server" 
                                Text='<%# Container.DataItem %>'>
                    </asp:Label>
                </ItemTemplate>
                <SeparatorTemplate>
                    <br />
                </SeparatorTemplate>
            </asp:DataList>
        </div>
    </form>
</body>
</html>

The first thing that you would notice on the code above is that we have assigned a value to the Text property of our Label control. This value signifies that we are binding the Container.DataItem value to the Text property. This DataItem will come from the value that we are going to set in the codebehind file for this page which in this case is just going to be a List<string>.

Next, lets go the codebehind file and create the Page_Load event for our page:

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //create a list of stock symbols
            List<string> listOfSymbols = new List<string>();

            //add some symbols to our list
            listOfSymbols.Add("MSFT");
            listOfSymbols.Add("GOOG");
            listOfSymbols.Add("CSCO");
            listOfSymbols.Add("MER");
            listOfSymbols.Add("F");

            //bind the list<string> to our datalist
            stockDataList.DataSource = listOfSymbols;
            stockDataList.DataBind();
        }
    }
}

All i did in the code above is create a list of strings, add some values to it and assign and bind that colletion of strings to our DataList. Running the application now would give us this result:

Nothing really impressive yet. Now let's add the cool part wherein we call a web service and show the information for each stock symbol.

To do that we need to add another DataList inside the ItemTemplate of our first DataList. The second DataList will serve as the list that shows the imformation about the specified execution symbol. We also need to add an event that is triggered each time a ListItem is binded to a data. Below is our modified HTML page:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Keith Rull's Consuming Web Services Sample</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:DataList   ID="stockDataList" 
                            runat="server" 
                            OnItemDataBound="stockDataList_ItemDataBound">
                <ItemTemplate>
                    <asp:Label  ID="quoteLabel" 
                                runat="server" 
                                Text='<%# Container.DataItem %>'>
                    </asp:Label>
                    <asp:DataList   ID="stockInformationDataList" 
                                    runat="server">
                        <ItemTemplate>
                            <table  cellpadding="1" 
                                    cellspacing="1" 
                                    border="0" 
                                    width="600px">
                                <tr>
                                    <td><b>Last:</b>&nbsp;<%# Eval("Last") %></td>
                                    <td><b>Date:</b>&nbsp;<%# Eval("Date") %></td>
                                    <td><b>Time:</b>&nbsp;<%# Eval("Time") %></td>
                                    <td><b>Change:</b>&nbsp;<%# Eval("Change") %></td>
                                </tr>
                                <tr>
                                    <td><b>Open:</b>&nbsp;<%# Eval("Open") %></td>
                                    <td><b>Low:</b>&nbsp;<%# Eval("Low") %></td>
                                    <td><b>High:</b>&nbsp;<%# Eval("High") %></td>
                                    <td><b>Volume:</b>&nbsp;<%# Eval("Volume") %></td>
                                </tr>
                                <tr>
                                    <td><b>MktCap:</b>&nbsp;<%# Eval("MktCap") %></td>
                                    <td><b>PrvClose:</b>&nbsp;<%# Eval("PreviousClose") %></td>
                                    <td><b>PerChange:</b>&nbsp;<%# Eval("PercentageChange") %></td>
                                    <td><b>AnnRange:</b>&nbsp;<%# Eval("AnnRange") %></td>
                                </tr>
                                <tr>
                                    <td><b>Earns:</b>&nbsp;<%# Eval("Earns") %></td>
                                    <td><b>P-E:</b>&nbsp;<%# Eval("P-E") %></td>
                                    <td>&nbsp</td>
                                    <td>&nbsp</td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </asp:DataList>
                </ItemTemplate>
                <SeparatorTemplate>
                    <br />
                </SeparatorTemplate>
            </asp:DataList>
        </div>
    </form>
</body>
</html>

I modified the ItemTemplate of our second DataList () and added an html table to hold the values that the web service returns. This way the view that we are presenting is much more readable.

Next stop is looking at the code behind where all these magic is going to be wired. All the work for the detail view will happen on the stockDataList_ItemDataBound event and no further modification to our Page_Load event is needed. Let me show you the code for that event before I start explaining every bits and pieces of that code:

protected void stockDataList_ItemDataBound(object sender, DataListItemEventArgs e)
{
    //check whether the current listitem is an acceptable ListItemType
    if (e.Item.ItemType == ListItemType.Item
        || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        //get the binded symbol
        string symbol = e.Item.DataItem.ToString();

        //find the datalist in our itemtemplate
        Control foundControl = e.Item.FindControl("stockInformationDataList");
        //cast the control to a DataList
        DataList stockInformationDataList = (DataList)foundControl;
        //get the stock information for the specified symbol
        DataSet stockInformationDataSet = StockQuoteHelper.GetStockQuoteDataSet(symbol);

        //bind the dataset to our datalist
        stockInformationDataList.DataSource = stockInformationDataSet;
        stockInformationDataList.DataBind();
    }
}

What we are doing on this blog of code is we are checking if the ItemType of the current item being binded-to is either a ListItemType.Item or ListItemType.AlternatingItem. If it passes this criteria we then read the DataItem that was binded to this ListItem which in this case is our executionSymbol. The next step is to find our stockInformationDataList control and assign the stockInformationDataSet to it. The stockInformationDataSet contains the values that is retrieved from our stock web service by passing the exection symbol to our StockQuoteHelper.GetStockQuoteDataSet method.

Running our completed application will result to this screen:

And that's it! We've accomplished a master-detail view in ASP.NET. Pretty easy right? I hope you learned something from this tutorial. Next up we'll update this project and implement some Asynchronous Web Service calls via ASP.NET AJAX and show you some fun ways to present a master-detail view in a much more interesting way.

As always, source code is available for download here: KeithRull.ConsumingWebServices.Part3.zip (6.9 KB)

As a side note, many thanks to John A. Miller from Trofholz Technologies, Inc. for reminding me about this series. I totally forgot about it already after being assigned to a large project the past few months. Thanks John!

.NET | AJAX | ASP.NET | Fun Stuff | Tutorial
Wednesday, October 22, 2008 8:21:07 PM (GMT Daylight Time, UTC+01:00) #    Comments [0]  | 

 

All content © 2010, Keith Rull
On this page
This site
Calendar
<March 2009>
SunMonTueWedThuFriSat
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234
Archives
Sitemap
Blogroll OPML
Disclaimer

Powered by: newtelligence dasBlog 2.3.9074.18820

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts


Pick a theme: