November 5th, 2015

Export Data to Excel (.xls, .xlsx) in ASP.NET – C#

In this article, we will see different ways to export data to Excel from a web application. It is very common task for web developers. Here are different approaches to do it in ASP.NETC#:

Approach 1:

Using the Excel PIA (primary interop assemblies) to generate a spreadsheet server-side.

It needs Microsoft Office suite installed on your server which is not good. So it is NOT recommended.

May 21st, 2015

A Better Way To Manage ASP.NET Session With Generic Wrapper

Before we get started, let us see the general way to use Session in ASP.NET

if (Session["UserName"] == null) 
    LabelUserName.Text = "Anonymous"; 
    LabelUserName.Text = (string)Session["UserName"]; 

You can feel some drawbacks e.g. to check null reference, type safety, to cast object..etc.

Now add following class and see how it solves the issues:

February 8th, 2014

Get Browser Height and Width on Server Side in ASP.NET

A Responsive Web Design is not only UI changes but also to optimize server side logic for performance. Suppose you are displaying bulk data in desktop environment. But if same data are sent to mobile device, it will make website too slow even the layout is made adaptive on client side. To implement server side logic, we need client side information like browser width and height. In this article, we will implement to get browser height and width on server side in ASP.NET.

February 3rd, 2014

Drill Down For ASP.NET 4.0 Chart Control

In this article, we will implement drill down for ASP.NET 4.0 built in chart control. On the first chart the data is grouped by year. The year is divided into quarters. By clicking on an item on the chart you can get the values corresponding to the quarters of the selected year. Each quarter consists of 3 months. After choosing a quarter for the selected year you can get the values for each month of the this quarter.

Environment: VS2012,.NET Framework 4.0, ASP.NET Web Form, C#, Entity Framework

September 10th, 2013

Combine Images into Facebook Style Collage in ASP.NET Web Forms

Facebook home page displays a collage of random profile photos which makes it something special. So I decided to implement the same thing in ASP.NET. In this tutorial, we will do following things:
1. To get random image names from database using Entity Framework Database First approach.
2. Calculate the total needed images for a given width and height. Assuming all profile images have same size.
3. Combine multiple images into collage using C# graphics
4. Add borders to differentiate images
5. Create linear horizontal opacity gradient for the collage and add it in a page similar to Facebook.

January 25th, 2013

Responsive ASP.NET GridView With Twitter Bootstrap

In my recent post, Responsive ASP.NET GridView is implemented using jQuery FooTable plugin. If you are using Twitter Bootstrap framework, you can easily show hide elements based on characteristics of the device the site is being displayed on, most commonly the width of the browser using the inbuilt CSS classes.