Yet Another Blog on ASP.NET and Some Other Stuff

Manual Sorting with ListView by Using Drag and Drop

Posted in ASP.NET, ListView, VB.NET, Web Development, XML by Mustafa Basgun on June 30th, 2008

Introduction

I have been following Matt’s jQuery related posts, and trying to get myself familiar with this new library. While searching for tutorials about it, I accidentally found this great blog. Accident followed by another accident, I figured out that one of their JavaScript posts can be applicable to the ListView control in order to create a “drag and drop” based manual sorting within the items of the ListView.

• I strongly suggest reading the original post first before passing to the rest of this post.

Implementing The Original Post…

As a data source, I just grabbed the XML file that I used before in here, and simplified it.

Here is the CSS implementation of the original post into my sample ASPX page:

And then, I created the DIVs programmatically by using a ListView as in the following:

If you look at the JavaScript.js file that I used in my sample code, you will see that the load function has been commented since I needed to create the “dragObject” objects dynamically in that function:

As a result of this, I organized the Page_Load event as:

Download

You can download the sample application via here.

Enhancing Paging in ListView by Using DataPager

Posted in ASP.NET, ListView, VB.NET, Web Development, XML by Mustafa Basgun on May 7th, 2008

DataPager is one of the new controls in ASP.NET 3.5, and it provides paging functionality for data-bound controls that implement the IPageableItemContainer interface, which is only the ListView control for the time being.

By default, DataPager has two commonly used paging styles:

• Numeric Pager via NumericPagerField

• Next and Previous Pager via NextPreviousPagerField

To get an idea about how to implement these basic common styles, you can read this post.

This post will explain how to enhance the paging experience in a ListView by using both a NextPreviousPagerField and a DropDownList which will enable users to select the page size of ListView. This page size is actually the PageSize property of the DataPager, and this property defines the number of records that are displayed for each page of ListView.

To avoid complexity, the following simple XML file (Contacts.xml) will be used as a data source:

And, the XMLDataSource that consumes this XML file is:

“xdsDemo” is the DataSourceID of the ListView “lvDemo”:

After getting this data binding done, LayoutTemplate of “lvDemo” should be similar to the following:

Even though it is not completely related with the topic and emphasis of this post, ItemTemplate and AltenatingItemTemplate templates of “lvDemo” are:

Finally, here is the code that sets DropDownList (ddlDemo) and DataPager (dpDemo):

As a conclusion of all these things, the result on the browser should be like:

Download

Sample code for this demo application can be downloaded via here.

“LINQ to XML” in ASP.NET - Ajaxified XML Document Filtering

Posted in AJAX, ASP.NET, LINQ, UpdatePanel, VB.NET, Web Development, XML by Mustafa Basgun on January 13th, 2008

Introduction

LINQ to XML is a new way to play with the XML data in .NET 3.5. It is actually an XML programming API that simplifies dealing with XML documents without any need to know about additional syntaxes such as XSLT and XPath. It is designed to be a cleaner, faster and lightweight API which at the same time has the key features from XSLT and XPath. According to MSDN, its public data model is aligned as much as possible with the W3C XML Information Set.

Sample XML Data and Its Filtering with “LINQ to XML”

For sampling purposes, I just created the following XML data and add it to my demo project:

My purpose is developing a simple ajaxified web application that has a dropdown with the country names and a literal that shows the capital city of selected country name from this dropdown. For this purpose, I created my server controls with some AJAX flavor as:

Then, I organized the Page_Load event as in the following in order to query over Countries.xml:

Pay attention to the usage of XDocument class from System.Xml.Linq namespace (which is already defined in the web.config file as default) in order to load the local Countries.xml file and the new casting and access methods (such as .Descendants and .Element that I used above).

Finally, after compilation the result on the browser should be like:

When “Belgium” is selected from the dropdown, literal will show the following with a partial rendering:

Conclusion

I generally work with SQL Server or Access in the data layers of my web applications, therefore I barely had a chance to put my hands on XSLT and XPath deeply. But, I can say that “LINQ to XML” as a data provider seems enough even powerful for me to handle many common XML programming tasks inside my code.

Download

You can download the demo project via here.