Archives

Archives / 2010
  • Adding an expression based image in a client report definition file (RDLC)

    In previous posts, I showed you how to create a report using Visual Studio 2010 and how to add a hyperlink to the report

    In this post, I show you how to add an expression based image to each row of the report. This is similar to displaying a checkbox column for Boolean values.  A sample project is attached to the bottom of this post.

    To start off, download the project we created earlier from here.  The report we created had a “Discontinued” column of type Boolean. We are going to change it to display an “available” icon or “unavailable” icon based on the “Discontinued” row value. 
     image
    Load the project and double click on Products.rdlc. With the report design surface active, you will see the “Report Data” tool window. Right click on the Images folder and select “Add Image..”
    image 
    Add the available_icon.png and discontinued_icon.png images (the sample project at the end of this post has the icon png files)

  • CascadingDropDown jQuery Plugin for ASP.NET MVC

    Cascading Drop Down is a jQuery plug-in that can be used by a select list to get automatic population using AJAX. The plug-in and a sample ASP.NET MVC project are attached at the bottom of this post.

  • Running a Silverlight application in the Google App Engine platform

    This post shows you how to host a Silverlight application in the Google App Engine (GAE) platform. You deploy and host your Silverlight application on Google’s infrastructure by creating a configuration file and uploading it along with your application files.

    I tested this by uploading an old demo of mine - the four stroke engine silverlight demo. It is currently being served by the GAE over here: http://fourstrokeengine.appspot.com/

  • Pre-filtering and shaping OData feeds using WCF Data Services and the Entity Framework - Part 2

    In the previous post, you saw how to create an OData feed and pre-filter the data. In this post, we will see how to shape the data. A sample project is attached at the bottom of this post.

    Pre-filtering and shaping OData feeds using WCF Data Services and the Entity Framework - Part 1

    Shaping the feed

    The Product feed we created earlier returns too much information about our products.

  • Pre-filtering and shaping OData feeds using WCF Data Services and the Entity Framework - Part 1

    The Open Data Protocol, referred to as OData, is a new data-sharing standard that breaks down silos and fosters an interoperative ecosystem for data consumers (clients) and producers (services) that is far more powerful than currently possible. It enables more applications to make sense of a broader set of data, and helps every data service and client add value to the whole ecosystem. WCF Data Services (previously known as ADO.NET Data Services), then, was the first Microsoft technology to support the Open Data Protocol in Visual Studio 2008 SP1. It provides developers with client libraries for .NET, Silverlight, AJAX, PHP and Java. Microsoft now also supports OData in SQL Server 2008 R2, Windows Azure Storage, Excel 2010 (through PowerPivot), and SharePoint 2010. Many other other applications in the works. *

    This post walks you through how to create an OData feed, define a shape for the data and pre-filter the data using Visual Studio 2010, WCF Data Services and the Entity Framework. A sample project is attached at the bottom of Part 2 of this post.

    Pre-filtering and shaping OData feeds using WCF Data Services and the Entity Framework - Part 2

  • Adding a hyperlink in a client report definition file (RDLC)

    This post shows you how to add a hyperlink to your RDLC report. In a previous post, I showed you how to create an RDLC report.

    We have been given the requirement to the report we created earlier, the Northwind Product report, to add a column that will contain hyperlinks which are unique per row.  The URLs will be RESTful with the ProductID at the end.

    Clicking on the URL will take them to a website like so: http://localhost/products/3  where 3 is the primary key of the product row clicked on.

    To start off, open the RDLC and add a new column to the product table.

  • Running ASP.NET Webforms and ASP.NET MVC side by side

    One of the nice things about ASP.NET MVC and its older brother ASP.NET WebForms is that they are both built on top of the ASP.NET runtime environment. The advantage of this is that, you can still run them side by side even though MVC and WebForms are different frameworks.

  • Creating an ASP.NET report using Visual Studio 2010 - Part 3

    We continue building our report in this three part series.

    Creating an ASP.NET report using Visual Studio 2010 - Part 1
    Creating an ASP.NET report using Visual Studio 2010 - Part 2

    Adding the ReportViewer control and filter drop downs.

    Open the source code for index.aspx and add a ScriptManager control. This control is required for the ReportViewer control. Add a DropDownList for the categories and suppliers. Add the ReportViewer control. The markup after these steps is shown below.

  • Creating an ASP.NET report using Visual Studio 2010 - Part 1

    This tutorial walks you through creating an ASP.NET report based on the Northwind sample database. It shows how to add a client report definition file (RDLC), create a dataset for the RDLC, define queries using LINQ to Entities, design the report and add a ReportViewer web control to render the report in a ASP.NET web page. The report will have a chart control. The result can be filtered by two drop downs at the top..

    At the end of the walkthrough, you should have a UI like the following.  As shown, there is a product list report with an embedded chart. The chart shows the sum of Unit price for a given category. It is possible to filter the results by Category and Supplier. The drop downs auto post back when the selection is changed.  This demo uses Visual Studio 2010 RTM.

    This post is split into three parts. The last part has the sample code attached.

    Creating an ASP.NET report using Visual Studio 2010 - Part 2
    Creating an ASP.NET report using Visual Studio 2010 - Part 3

    image 

    Lets start by creating a new ASP.NET empty web application called “NorthwindReports”
    image
    Creating the Data Access Layer (DAL)

  • Autopostback select lists in ASP.NET MVC using jQuery

    This tiny snippet of code show you how to have your select lists autopostback its containing form when the selected value changes.

    When the DOM is fully loaded, we get all select nodes that have an attribute of “data-autopostback” with a value of “true”.

    We wire up the “change” JavaScript event to all these select nodes. This event is fired as soon as the user changes their selection with the mouse. 

    When the event is fired, we find the closest form tag for the select node that raised the event and submit the form.

  • ActionResult types in MVC2

    In ASP.NET MVC, incoming browser requests gets mapped to a controller action method. The action method returns a type of ActionResult in response to the browser request. A basic example is shown below:

  • Editing Project files, Resource Editors in VS 2010

    Editing Project Files

    Visual Studio gives you the ability to easily edit the project file associated with your project (.csproj or .vbproj). You might do this to change settings related to how the project is compiled since proj files are MSBuild files. The ability to edit project files has been available in previous versions of Visual studio and is not a new feature.

    One would normally close Visual Studio and edit the proj file using a text editor. 
    The better way is to first unload the project in Visual Studio by right clicking on the project in the solution explorer and selecting “Unload Project”

  • Localization in ASP.NET MVC 2 using ModelMetadata

    This post uses an MVC 2 RTM application inside VS 2010 that is targeting the .NET Framework 4.

    .NET 4 DataAnnotations comes with a new Display attribute that has several properties including specifying the value that is used for display in the UI and a ResourceType. Unfortunately, this attribute is new and is not supported in MVC 2 RTM.

  • Setting up Visual Studio 2010 to step into Microsoft .NET Source Code

    Using the Microsoft Symbol Server to obtain symbol debugging information is now much easier in VS 2010. Microsoft gives you access to their internet symbol server that contains symbol files for most of the .NET framework including the recently announced availability of MVC 2 Symbols. 

  • ASP.NET Dynamic Data Deployment Error

    You have an ASP.NET 3.5 dynamic data website that works great on your local box. When you deploy it to your production machine and turn on debug, you get the YSD

  • ASP.NET Asynchronous Pages and when to use them

    There have been several articles posted about using  asynchronous pages in ASP.NET but none of them go into detail as to when you should use them. I finally saw a great post by Thomas Marquardt that explains the process in depth. He addresses a key misconception too:

    So, in your ASP.NET application, when should you perform work asynchronously instead of synchronously? Well, only 1 thread per CPU can execute at a time.  Did you catch that?  A lot of people seem to miss this point...only one thread executes at a time on a CPU. When you have more than this, you pay an expensive penalty--a context switch. However, if a thread is blocked waiting on work...then it makes sense to switch to another thread, one that can execute now.  It also makes sense to switch threads if you want work to be done in parallel as opposed to in series, but up until a certain point it actually makes much more sense to execute work in series, again, because of the expensive context switch.

    Pop quiz: If you have a thread that is doing a lot of computational work and using the CPU heavily, and this takes a while, should you switch to another thread? No! The current thread is efficiently using the CPU, so switching will only incur the cost of a context switch.

    Ok, well, what if you have a thread that makes an HTTP or SOAP request to another server and takes a long time, should you switch threads? Yes! You can perform the HTTP or SOAP request asynchronously, so that once the "send" has occurred, you can unwind the current thread and not use any threads until there is an I/O completion for the "receive". Between the "send" and the "receive", the remote server is busy, so locally you don't need to be blocking on a thread, but instead make use of the asynchronous APIs provided in .NET Framework so that you can unwind and be notified upon completion. Again, it only makes sense to switch threads if the benefit from doing so out weights the cost of the switch.

  • Code snippets for ASP.NET MVC2 in VS 2010

    VS 2010 comes with ready made snippets which helps you save time while coding.

    You insert a snippet by typing the name of the code snippet and hitting the Tab key twice. You can also use the following method if you wish to see a listing of snippets available.

  • ASP.NET MVC Paging/Sorting/Filtering a list using ModelMetadata

    This post looks at how to control paging, sorting and filtering when displaying a list of data by specifying attributes in your Model using the ASP.NET MVC framework and the excellent MVCContrib library.

    Please see this post for a way of rendering the UI without using custom Sorting and Filtering attributes.

    It also shows how to hide/show columns and control the formatting of data using attributes. 

    This uses the Northwind database. A sample project is attached at the end of this post.

  • Securing an ASP.NET MVC 2 Application

    This post attempts to look at some of the methods that can be used to secure an ASP.NET MVC 2 Application called Northwind Traders Human Resources

    The sample code for the project is attached at the bottom of this post.

    We are going to use a slightly modified Northwind database. The screen capture from SQL server management studio shows the change. I added a new column called Salary, inserted some random salaries for the employees and then turned off AllowNulls.

  • Using Delegates in C# (Part 1)

    This post provides a very basic introduction of delegates in C#.

    Part 2 of this post can be read here.

    A delegate is a class that is derived from System.Delegate.  It contains a list of one or more methods called an invocation list. When a delegate instance is “invoked” with the arguments as defined in the signature of the delegate, each of the methods in the invocation list gets invoked with the arguments. The code below shows example with static and instance methods respectively:

    Static Methods

  • Joins in LINQ to SQL

    The following post shows how to write different types of joins in LINQ to SQL. I am using the Northwind database and LINQ to SQL for these examples.