How to enable Listview Databinding in LayoutTemplate
October 13th, 2009I am a big fan of the ListView control in ASP.NET 3.5. Though I discovered that databinding code can't be used inside the layout template. Recently I had a simple scenario where I wanted to automatically display an arrow on the header of every sortable column.
Even the famous Matt Berseth did not manage to handle this scenario in a simple manner. If you look at the code behind, you'll see he has to handle the OnDataBinding method to check every column header and add an arrow dynamically on the sorted column.
I have found a solution which allows me to had this behavior declaratively, and even more important, simply.
Now in the layout I just have to set this binding expression:
<th class=<%# ContactsLV.SortExpression == "LastName"
? (ContactsLV.SortDirection == SortDirection.Ascending
? "sortedASC" : "sortedDESC")
: "notSorted" %>>
Where ContactLV is my listview, and LastName is the SortExpression.
To be able to handle this data binding code, the ListView has to call DataBind() on elements in the LayoutTemplate. I have created an Adapter for this purpose, and registered it in the Browser file.
The code is also really simple:
public class ListViewAdapter : ControlAdapter
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
((ListView)Control).DataBound += (sender, args) =>
{
if (Control != null && Control.Controls.Count > 0)
{
foreach (Control elt in Control.Controls[0].Controls)
{
if (elt is ListViewDataItem)
{
continue;
}
elt.DataBind();
}
}
};
}
}
The declaration in the BrowserFile.browser:
<browsers>
<browser refID="Default">
<controlAdapters>
<adapter controlType="System.Web.UI.WebControls.ListView"
adapterType="Microsoft.Web.Adapters.ListViewAdapter" />
</controlAdapters>
</browser>
</browsers>
And the result:
As you can see, I have used three states: notSorted, sortedASC and sortedDESC. On the image, every column not sorted has an up/down arrow, and the Title column is sorted ascending. Clicking on any other row will send a Sort command to the underlying data source, and also automatically (and magically) refresh the arrows.
ECMAScript vs. JavaScript
October 11th, 2009In my long road to the implementation of a .NET JavaScript interpreter, I discovered that I actually knew little about JavaScript. For instance I discovered JavaScript could do for each loops, had the yield statement as in C#, lambda expressions and even XML instructions.
This is just a subset of what JavaScript defines. But the reason why we neither know nor use those feature is that JavaScript is not ECMAScript. The latest is the standardized version of the first, and they don't follow the same timeline. The one we usually know is ECMAScript 3.0.
As a matter of fact ECMAScript 3.0 (also named ES3) is equivalent to JavaScript 1.5. Those versions are used in Internet Explorer, Safari and Opera. Chrome is compatible with version 1.7 and FireFox 3.0 uses JavaScript 1.8 definition. For cross browser scripts, it's obvious that all developers then use the JavaScript 1.5 (ES3) version.
Next big step is to see all browser implement ECMAScript 4.0, which is supposed to be equivalent to JavaScript 2.0, and embeds all concepts I have enumerated above.
Here is a list of very interesting readings:
New in JavaScript 1.6
New in JavaScript 1.7
New in JavaScript 1.8
John Resig's posts (jQuery's father) about ECMAScript
Update
Bertrand corrected me on ES4. Actually this version will never see the light in standard browsers (instead of FF which already implements it). The reason is that it never went to enough acceptance from other editors (Yahoo and Microsoft for instance), and two different paths were followed. Fortunately they joined back to a more simple evolution of ECMAScript, i.e. ES3.1 later renamed ES 5. This should become standard implementation at the end of this year, thus I can't but follow it also ;). Thank you Bertrand for the information (as usual).
Lost feeds
October 6th, 2009My main way of getting information is by using rss feeds. They can be blogs, sites or specialized opmls. For this I use Internet Explorer exclusively, as it shows everything not yet read, and doesn't need a live connexion for it.
Though there is an issue. Actually some feeds seem to miss activity from time to time. Yesterday I clicked on an unmodified rss feed, and IE displayed it was no more available. The rss url had changed, because the hosting software had been switched. I then checked every single feed in my list and I somehow rediscovered interesting posts. (e.g., Steve, Vincent)
Do you have such an issue from your side ?
The unknown Javascript
Septembre 23rd, 2009Jint - Javascript interpreter for .NET
September 22nd, 2009I have published a new project on codeplex. It's called Jint.
Jint is a script engine based on the Javascript language. Using Jint, developers can provide fully scriptable applications, execute .NET code without compiling, or create external configuration logic, using the most used script language.
Jint aims at providing every JavaScript functionalities to .NET applications, and bindings to .NET languages can be done in both sides. Jint scripts can use any .NET object from your application, and use every part of the .NET base class library.
Enjoy on http://jint.codeplex.com.
ASP.NET Themes
May 13th, 2009When I was a young developer I did not like Themes in ASP.NET, I prefered pure CSS.
Also, when I was a young boy I did not like girls, I prefered sweets. Did not think loving one did not prevent from loving the other.
Internet Explorer 8 consumes too much memory
April 24th, 2009Since I have installed IE8, sometimes it starts consuming a lot of memory, about 500Mb, and is very very slow on "postbacks". It sometimes made me switch to Firefox where the sites where very fast. Actually it was my fault.
I very often debug HTML/Javascript code or analyse the techniques to enhance my knowledge. For this I have used the Developer Toolbar, and now with IE8 the integrated one. What I do is minimize it and thus I always have it ready to use. And this is actually the issue, it just loads the whole DOM again into memory with the perforamnce impact you can imagine.
So if you find Internet Explorer to be slow and consume lot of memory, close the development toolbar.
Localized CSV format and Excel
February 18th, 2009I've just learnt that the CSV format is culture specific. It means that depending on your regional settings Excel for instance will understant or not CSV files it opens.
For instance say I have a French version of Excel, if I open a "comma" separated value like a,b,c,d I would only have one column. But using the line a;b;c;d it will work. On an English version of Excel, it would be exactly the oposite.
This character (coma or semi-colon) is called the List Separator in your regional settings, and in .NET, to get this value we can use the CultureInfo.TextInfo ListSeparator property.
jQuery
January 14th, 2009jQuery is like doing sex for the first time: there is a life before and a life after.
And you, where are you ?
Blog renamed
January 9th, 2009Today I renamed my blog to Potash Valley as I am based in the Mulhouse Potash basin. I find it funny :)
French accents and international keyboards
December 22nd, 2008Alternate title: Why you never asked why some keyboard's letters wait for an additional character to be hit.
Do you know that French is full of accents ? For instance my first name has one: Sébastien. I usually receive emails with Sebastien. That's not important but I think this is because none French keyboards owner can't write such letters. I also have this issue when working for international companies on their computers. Here is some tips to write those letters.
Combine two letters to form only one like this:
' + e/c → é/ç
` + a/e/u → à/è/ù
^ + a/e/i/o/u → â/ê/î/ô/û
" + e/i/u → ë/ï/ü
For capital letters hold SHIFT while pressing the letter you want to accent.
But the shortcuts for é and ç only work with US-International keyboards. For the Swiss keyboards and also French who'd like to create special capital letters use this shortcuts:
é = ALT + 130
É = ALT + 144
ç = ALT + 135
Ç = ALT + 128
NB: this is the same for Spanish letters with ~ like ã and ñ.
What I found great at PDC – Day 2
November 10th, 2008The second day at PDC was almost a keynote day as the whole morning was focused on annoucements. Though, I managed to attend very interesting sessions.
TL14 Project "Velocity": A First Look
Before going to this session I knew what Velocity was for: distributed data caching. I also knew about difficulties to implement such a framework as I have already created one for Data Tier Modeler, our old ORM framework. Going to this session was a great pleasure as it answered a lot of my questions, especially about all the available features, and real scenarios applications. Definitely one of my next development topics.
BB43 Identity: "Geneva" Deep Dive
I didn't really what it would be about but this session was very instructive. Not only did we learned about all issues concerning authentication on the cloud, but also some solutions, with our without Geneva. If you have to deal with network administration or just are a developer focusing on the cloud, don't hesitate. The demonstrations did not work smoothly but the expected results were meaningful though.
TL20 Entity Framework Futures
Entity Framework is a great initiative from Microsoft. But this session did not reach the expectations I had. We learned how to do the simplest thing ever with an ORM tool, and people applaused ! Hey guys, this example was trivial ! Mapping a table with two columns to a POCO ? That's not "Futures". At least this shows what we could expect for next versions, but those features are already implemented in lot of open frameworks. At least, it's better than LINQ To SQL.
Universal Studio
As last time Microsoft invited everyone to visit the Universal Studio Park. Always great, free food, free amusements, including new ones: Simpsons replacing Star Wars, and a scary tour instead of the usual studio visit :>
What I found great at PDC – Day 1
November 4th, 2008No, I did not only learned how to hide the ribbon ;) I also saw a lot of great sessions. In this series of four posts, one per attendance day, I will give you what sessions I think are worth seeing as a developer’s perspective. As I couldn’t be everywhere at the same time, I missed a lot of great other ones and I hope I’ll be able to see them also.
TL33 Managed Extensibility Framework: Overview
MEF is great thing, really. It’s very simple to use and adapted to real extensibility scenarios. The session was pretty good, with clear examples, and easy to understand. A question which is still pending in my mind is the coherence with other Microsoft tools like System.Addin and Unity. MEF could be a winner if it is adopted by developers as it is internally at Microsoft. Hum, this reminds me something related to data access, don't you ?
TL10 Deep Dive: Dynamic Languages in Microsoft .NET
This is a great session if you like dynamic languages. Jim is clever! Though, a lot of his examples were “stolen” by Anders Hejlsberg which was repetitive if you had assisted to this session also. If you want a headache at the end of the day, just watch this session. Not only is it really difficult to understand all the concepts he dealt with, but he also speaks really fast. Poor little French guys were we.
ES01 Developing and Deploying Your First Windows Azure Service
I have not seen this session at the PDC directly but at home. This is a great session to understand all the concepts behind programming for the Azure platform. Tables, Queues and blobs are well explained, and this is the only place where I had an answer whether a developer should use Azure storage or SDS.
What I learned at PDC
November 2nd, 2008Did you know that you can hide the ribbon and let it appear when the mouse hovers it by double clicking on any of the sections ?
PDC is fantastic, looking forward to going there again !
My PDC
October 30th, 2008I have now finished my third day at PDC. So far a lot of interesting new products and functionnalities have been introduced.
Azure
Among the most interesting and important announces Azure is the top one. As a developper perspective it's not so interesting, I admit. But as an ISV it should have a huge impact on how we work, and more particularely on the real business. For those who are not aware (if there is any) Azure provides hosting services for any ASP.NET web application. This means we can grow as far as we want, simply, and we hope it will be cheap. Currently ASP.NET is far behind PHP in terms of hosting costs and services. I hope and trully think that this will reduce this gap, with a deep focus on websites.
C# 4.0
Good stuff, but I don't think those changes are important for the common grammer.
Yes it will add a lot of possibilities but those concepts are too far from reality. I currently know a few companies who really use the power of C# 2.0, I even don't want to tell about C# 3.0. But more is better than less, and it has the advantage to tremendously simplify the interoperability code for COM and the Office suite.
Windows 7
As a developer the functionality which is most interesting is the ability to create bootable virtual machines. We will be able to take the full advantage of our hardware on predefined development environments.
Visual Studio 2010
The only interesting stuff I have seen so far is UML 2.4 management. Again a business killer functionnality, integrated inside the environment. Great for the users, with great looking designs also. We can already use it in our presentations.
WCF and WF
Those new versions will not only increase dramatically the performance but also correct all the issues we can have currently: lack of textual representation, versionning. The only problem is the release date : late 2009. We need this now !
Quadrant
Quandrant is a visual data management tool for diagraming. It can diagram anything, and is fully configurable using itself as configuration diagrams. Technically it uses MVC everywhere and nothing useful for the developer can be used. But the paradigms are very interesting. We'll have to wait for more practical stuff.
Looking forward for the last day.