I handed a DataSet over to a DataGrid and had it display the only table in that DataSet. One of the columns in the table contained the unique identifier for the row. Later, I asked the DataGrid for the data on a certain row, in the unique identifier column. I was quite surprised when what I was given didn’t match with the data in the DataSet.

I was surprised, but it was obvious what was happening. My data was a single space and the DataGrid gave me the HTML code for non-breaking-space,  .

I was not keen (to say the least) on introducing HTML decoding into my thin UI layer, whether the end result is HTML or not! I would if it was absolutely necessary, but of course I prefer my code to work in isolation. I say of course, but I just spoke to someone who didn’t seem to understand why this is a Good Thing™.

The solution for me was simple: use the ID stored in the DataGrid’s DataKeyField and look up the identifier I really needed.

When I’m designing a class which will hold information, I always try to ensure that the user of the class can get information back which they have handed over. This is called politeness. To allow them to retrieve the information - but silently mangle it - is impolite in the extreme.

I’m a fan of DataGrid. It has quirks, but it helps me develop faster, so I’m happy. This wasn’t a complaint, just a warning to those who haven’t noticed this behaviour yet.

No comments