Saturday
Jan102009

Linq to SQL basic list/grid view and form view

Lately I've been getting more and more into using Linq to SQL and think it rocks, Linq takes care of all the hard back end database functions so that you can focus on the interesting business logic of fun design and styling. I've been doing some research on the basics of Linq and found that most tutorials only show the List/GridView. However there was not many tutorials on working with Forms. So I have put together this basic tutorial to get you started. I have to give a lot of credit to aDefWebserver for this tutorial http://www.adefwebserver.com/DotNetNukeHELP/LinqTutorial2/LinqTutorial2_3.htm which although it specific to DotNetNuke a lot of the concepts can be learned here.

I have created a very basic database called "Contacts" with a table called "MyContacts", here is a screenshot of this table.

I prefer to set up a new database user now for this specific application so that when it comes to deploying the application your ready to go.

 

Now I will create a New Web Site in Visual Web Developer 2008 Express Edition called "MyContacts"

 In the Database Explorer right button click on the Data Connections root and select Add Connection

Add a new Linq to SQL Classes item called "My_Contacts_DataClass.dbml" under the App_Code folder

Once the My_Contacts_DataClass opens drag the "MyContacts" table onto the data class from the Database Explorer

 

Add a new web form called "List_MyContacts.aspx" for the list/grid view

Add a LinqDataSource from the Data section in the Toolbox to your new List_Mycontacts page and select Configure Data Source

Select the My_contacts_DataClassDataContext object and click next

Click the "Advanced" button and select which options you want to allow from the list/grid view. In this case I only want to allow Delete

Add a GridView from the Data section in the Toolbox to your new List_Mycontacts page and select the LinqDataSource1 as the Data source. Then check Enable Deleting and Selection so that the user can either delete the record directly from the list or select it to view it in the form view mode.

Select the GridView control and open the properties and click on the lightning bolt to see the events. Double click on the SelectedIndexChanged event and enter the following line of code within this SelectedIndexChanged procedure. This code will open the update page with the selected record in the form view.

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

    {

        Response.Redirect("Update_MyContacts.aspx?ContactId=" + Convert.ToInt32(GridView1.SelectedDataKey.Value) + "");

    }

 

Add a new web form called "Update_MyContacts.aspx" for the form view

Add a LinqDataSource from the Data section in the Toolbox to your new Update_Mycontacts page and select Configure Data Source

Select the My_contacts_DataClassDataContext object and click next

Click the "Advanced" button and select which options you want to allow from the list/grid view. Here I want to allow Insert, Update and Delete

Also click on the Where button and select the Contact_Id is equal to the a parameter passed via the query string so that when a user selects an item on the list/grid view page the update form will know which item the user wants to edit. Add the where clause

 

Add a FormView from the Data section in the Toolbox to your new Update_Mycontacts page and select the LinqDataSource1 as the Data source.

That's it now you can open your browser and browse the application. Here is the first page the list/grid view

When you click on the Select link in the grid view the page redirects to the Update page to display the form view in read only mode

 

Now when the user clicks on the Edit link the form will automatically switch into update mode so they can update the data and save it

Now that all of the data access functionality has been automatically created by Linq all you need to focus on is design and logic.

 

Friday
Jan092009

Theme Visual Studio your way

After using TextMate to do some Ruby on Rails development I got used to and enjoyed working on a darker themed editor, I've probably come late to the party but you can achieve the effect in Visual Studio by changing your settings.

Enjoy coding more at the same time saving the planet (only if you choose a dark background), I chose Rob Conery's TextMate theme.

Scott Hanselman has compiled a good collection of themes check it out.

 

Friday
Jan092009

960 degrids of separation

Well not really, after using divs to layout my web pages for some time now I decided to try the 960 CSS Framework. It's a welcome change from doing a load of floats.

I recommend reading Stefan Vervoort's post on divitodesign to get started, there are also some good examples provided in the downloadable zip.

This is purely a layout framework which helps you separate your content into columns of 60px, I know of other CSS frameworks that do a lot more.

What CSS frameworks do you know of and/or use?

Monday
Dec152008

Merry Christmas 2008

Merry Christmas and Happy Holidays to all of our valued customers and friends.

Thank you for all your support during 2008 and here's to an exciting 2009

We will be taking a break from the 20th December 2008 to 12th January 2009

 

Tuesday
Dec092008

How do you mock up application screens

There are so many different ways to mock up prototypes of application screens and web pages. From the good old favourite pencil and paper then scan it to an image all the way to the hard core designers favourite illustrator.

I'd probably have to say that just HTML in either Expressions or Visual Studio would be the main one for me as it's agile, quick, easy to change and is already a start into the development process.

However if you don't know HTML and probably don't want to there are still a stack of options for you. These include basic Microsoft PowerPoint, which surprisingly isn't that bad and has a lot of effects you can apply to fields and button to a very cool FireFox application called "Pencil". If you are looking for a cheap quick and easy way to prototype an application interface I'd say Pencil is definitely worth a try. 

If you use Pencil I'd love to hear some feedback or if you have a better alternative let me know