Changing Gridview column width in ASP.NET

August 8, 2011 Leave a comment

Today’s tip is a quick but handy one. Gridview is one of the most useful data tools in ASP.NET. By only configuring a datasource using the provided visual “wizard” you will be able to display and even edit your database without writing a single line of SQL or ASP code. Gridviews are  customized easily using the Autoformat feature in the Smart Tag or the property window. However sometimes you do need to write a bit of code to tweak the Gridview’s appearance.

Column’s width are not visually customizable and you need to do this in ASP:

When you drag an drop a Gridview into your project and assign a datasource to it, Visual Studio automatically writes the following ASP code for you which looks like the following code:

<asp:gridview runat="server" AutoGenerateColumns="False" 
        DataKeyNames="ApplicationId" DataSourceID="SqlDataSource2">
        <asp:BoundField DataField="ApplicationName" HeaderText="ApplicationName" 
            SortExpression="ApplicationName" />
        <asp:BoundField DataField="LoweredApplicationName" 
            HeaderText="LoweredApplicationName" SortExpression="LoweredApplicationName" />
        <asp:BoundField DataField="ApplicationId" HeaderText="ApplicationId" 
            ReadOnly="True" SortExpression="ApplicationId" />
        <asp:BoundField DataField="Description" HeaderText="Description" 
            SortExpression="Description" />

Now if you notic all column filed tags are closed. (< asp:… />) We want to add an element to the columns so we need to change the tags to  <asp….></asp…>

Now we can use ItemSyle like this:

<asp:BoundField DataField="ApplicationName" HeaderText="ApplicationName" 
            <ItemStyle Width="40px" />

This will fix the width of our column to 40 pixels.

Categories: .NET

MD5 password encryption in C#

August 2, 2011 Leave a comment

Password protection is very important for applications that store users’ passwords. One of most secure and commonly used approaches is to only(and only) store the encrypted version of the passwords and not themselves.

The most famous  Encryption algorithm is called MD5. Message Digest is a 128bit hash which although has been broken several times, is still serving a lot of applications.

identical strings will result in identical encrypted versions therefore all a developer needs to do is to MD5 the password first time it’s presented to the website. from then on every login the entered password is encrypted and compared against the stored pass.

Here is how you do this in Visual Studio using C#:

1-Importing necessary system parts:

using System.Security.Cryptography;
using System.Text;

2-Using the MD5 class

 byte[] pass = Encoding.UTF8.GetBytes(strChange);
 MD5 md5 = new MD5CryptoServiceProvider();
 string encryptedPass = Encoding.UTF8.GetString(md5.ComputeHash(pass));


August 1, 2011 Leave a comment

I’ve been working at a well known company since July as a summer intern writing a robust web portal that is going to serve 1300 of other companies we deal with world wide.

When I started I was told to use a WAMP stack but then within few days their requirements changed to Microsoft .NET and I hadn’t even touched it before apart from a minor experiment I recently did with the Kinect SDK. And to be honest being a  fan of the big G and open source I didn’t even want to try Microsoft’s package but then I had to.

Long story short, I started with .NET framework and Visual Studio 2010 Web Developer Edition just over a month ago and I have to admit it is actually one the best and most pleasant coding environments I’ve used. A very logical approach to OOP and the brilliance of ASP.NET controls made it really easy for me to pick it up.

I am now convinced enough to continue using and learning  .NET technologies.

Since the task I’m supposed to finish (by a slightly unfair deadline) involves a lot (and I mean it, a lot) of different aspects of it so far and I have to learn so fast that sometimes I forget what I knew yesterday, I decided to share important things I learn here. To help beginners like myself and for my own reference in the future.

Categories: .NET

Car Information System

May 25, 2011 Leave a comment

Car Informatic System (CIS) is an open source project I did as my final year project for my BEng degree. CIS provides the essential tools for tracking and monitoring vehicles. CIS allows access to Engine Control Unit (ECU) using OBD-II platform and also vehicle’s current position using GPS. This information can then be sent to a web server over a GPRS link or stored on a USB memory stick. A RFID reader is used to provide authentication and audio in-out ports are available in order to make phone calls if needed.

A website is developed which receives the information and stores them in a database and then presents them in various ways using maps, graphs, tables etc.

An iOS application is also developed which allows accessing the information on the go.

The goal of this project is not to make a product but to provide a platform that others can adopt and fine tune for their specific use. Various hardware components were studied in order to find a cheap but stable solution. The embedded, web, and mobile codes are well documented and anyone with basic electronic and programming knowledge can easily understand and weak CIS to match their requirements.

CIS can potentially be used to track stolen vehicles, monitor driving behaviour for delivery vehicles, Monitor engine’s performance for maintenance purposes, etc.

More detail and source code on this project will be published on HTMLTypewriter in the following weeks.

Categories: CIS

Visualized iPhone Tracker

May 15, 2011 Leave a comment

iPhone Tracker

We all remember Peter Warden and Alasdair Allan, the guys who discovered Apple’s secret location tracker software in their iOS devices that stored your device’s location up to around 100 times per day. don’t we?

Well you can see your own database decrypted and better yet visualized. Peter’s small app (for OS X) looks for the locationD file on your iOS backup file on your mac and visualizes it using OpenHeatMap a tool that he wrote himself.

Apple’s disabled this piece of software in the latest release of iOS which is said to be exclusively rolled out for this very reason. So if you happen to be a day-one-upgrader, well, you’ve missed the fun!

Source: iPhone Tracker

Categories: Apple

“Just do it ALL in Photoshop”

April 27, 2011 Leave a comment

We’re all aware of the awesomeness Adobe’s Photoshop and yes the new features in CS5 blew us away but hey did you know that you can actually make animations with Ps? no flash, no illustrator “do it all in photoshop”. These folks at Three Legged Legs have done an amazing job. check it out!

Categories: Uncategorized

//us idiots and morons

April 25, 2011 Leave a comment

Apparently, two files containing Microsoft’s win2k source code have been leaked and are being spread over p2p networks. Now, clearly Microsoft doesn’t want it’s code to be looked at for all the obvious reasons but ut in this case, there are rather funny bits in there that are quite a bit impressing.

If you’re not familiar with programming, I should explain that programmers often include  some ‘comments’ in their code which explains that a bit of their code and is used for future references. these comments in begin with a indicator such as “//” which tells the compiler that this is plain text and is not considered a part of the code.  Now Microsoft developers seem to be quite sure that their code is not viewed by anyone. here’s a few examples:

There are also various references to idiots and morons, some external, some within Microsoft. The file private\ntos\rtl\heap.c, which dates from 1989, tells us

// The specific idiot in this case is Office95, which likes
// to free a random pointer when you start Word95 from a desktop
// shortcut.

The file private\ntos\w32\ntuser\kernel\swp.c from 11-Jul-1991 points at

* for idiots like MS-Access 2.0 who SetWindowPos( SWP_BOZO
* and blow away themselves on the shell, then lets
* just ignore their plea to be removed from the tray

Morons also abound, as in this selection

// we are such morons. Wiz97 underwent a redesign between IE4 and IE5private\shell\ext\ftp\ftpdrop.cpp:
We have to do this only because Exchange is a moron.

// We are morons. We changed the IDeskTray interface between IE4

// should be fixed in the apps themselves. Morons!

Embarrassing isn’t it?! For more examples and info hit here.

Categories: Microsoft