Thursday, February 19, 2009

Sort a Data View Web Part based on QueryString

There was a requirement where I have to sort a data view webpart on multiple parameters like date, size and LOB. Initially I thought of having three different pages for sorting, but that is very bad idea. So thought of implementing it with the concept of query string.

I want to use the sort option provided by data view web part and provide SortField as query string parameter. After thinking for a while and providing multiple hit and trials I have succeeded. Below is the expression for sorting using query string.

@*[name()= $SortField]

We write this in the edit sort expression.

And in the URL….

http://ServerName/Lists/Deals/LOB.aspx?LOB=All&SortField=Deal_x0020_Date



Thursday, February 12, 2009

Apply multiple conditions to filter data in Data View web part

I was wondering if there is a way to filter the data present in data view web part by applying multiple conditions like this

If((@ApprovalStatus = 'Approved') and (@LOB = $Param1 or $Param1 = 'All'))

After thinking for sometime, I got an idea to add XSLT filtering instead of applying filter criteria available.



So I have checked the checkbox “Add XSLT filtering”, clicked on edit and added the following XSLT like this:

[(@ApprovalStatus = 'Approved') and (@LOB = $Param1 or $Param1 = 'All')]

Sunday, February 8, 2009

Displays one announcement at a time using DataView webpart

I had a requirement in my project where I had to customize the display of announcements. I was supposed to display single announcement at a time, providing the provision for the user, to navigate through the list of announcements one by one. User should be able to view next, previous and all the announcements. This needs to be done without writing any code.

Here is my approach for this problem. I have created a view for the announcements list which contains required columns along with the Id column. ID column is mandatory for this approach. Using SharePoint designer, in the announcements list I have created a custom form. Use this custom form to display one announcement at a time. Place a data view webpart on this form and customize it to accept query string for ID column to display that announcement.

Place Bank To all View Previous View Next links on the top and bottom of the webpart in this way.



Use the following JavaScript to access and display one announcement at a time.