2

XML, Linq, GridView, Label

by volkanuzun 18. May 2008 08:59

I had a very small project, where there would be page that lists events, another page that adds events. I didnt want to have a database for this simple pages, so i decided to go on with xml file. My xml file structure is basically like below: 


Now i need a pagethat will list all the events (hopefully ordering them according to When attribute which is a datetime. so i created a page put a label on the page, and open the code behind file.

What i want to do is, open the xml file, order them, and dump the data into the label, so i decided to use linq, as i am learning this new technique. Below is the simple code for this, linq made it so easy for me to parse the xml; unbelievable:

 


BTW you could do the exact same thing with xmldatasource and xpath, however; i am not sure with ordering :), ordering wont be that easy i guess with xmldatasource, here is the page that does the above listing with xmldatasource and gridview and xpath:

 

Tags:

Comments

Gürkan Yeniçeri
Gürkan Yeniçeri Australia
5/21/2008 3:41:08 PM #

Using xmldatasource; ordering can be done with a style sheet (xsl) suitable for your xml data.

volkanuzun
volkanuzun United States
5/21/2008 4:50:22 PM #

Himm i really didnt know that, can u sort according to datetime or  sorting on strings ?

Comments are closed

Powered by BlogEngine.NET 1.6.0.0
Original Design by Laptop Geek, Adapted by onesoft