Friday, April 28, 2006

 

BoundField.DataFormatString does not handle DateTime formatting

BoundField.DataFormatString does not handle DateTime formatting. If you would like to set the format for a DateTime field -- say displaying the date with only "{0:d}" you've got to set an additional parameter: HtmlEncode = false.

So, if you're creating things on the fly:

BoundField aColumn = new BoundField();
aColumn.DataField = "MyDateField";
aColumn.DataFormatString = "{0:d}";
aColumn.HtmlEncode = false;

GridView aGrid = new GridView();
aGrid.Columns.Add( aColumn );

This is not earth-shattering news. Raj Kaimal and others reported it much earlier. Raj notes that the BoundField applies HTML encoding before the data formatting. That makes sense.

What was most frustrating about this -- and consequently caused me to burn time -- is that the decision to apply HTML encoding before data formatting is NOT consistent across server controls. It's not even consistent among the classes that extend the DataCountrolField class.

In one of the CompositeControls that I've constructed I have a GridView that holds data that is generally unique by date. To save space I chose to create place the date into a ButtonField and let the ButtonField trigger the "Select" command:

ButtonField aColumn = new ButtonField();
aColumn.ButtonType = ButtonType.Link;
aColumn.DataTextField = "MyDateField";
aColumn.HeaderText = "MyHeaderText";
aColumn.CommandName = "Select";
aColumn.DataFormatString = "{0:d};

GridView aGrid = new GridView();
aGrid.Columns.Add( aColumn);

Guess what... this works! It just so happens that I tried this before I tried formatting the BoundColumn so I really thought I was screwing up the latter somehow.

So, which one is the buggy control, BoundField or ButtonField???

Wednesday, April 19, 2006

 

Make Moussaoui Live

Zarcarias Moussaoui, the Al Qaeda terrorist who would have taken part in the 9/11 hijackings if any of the hijackers had been unable, should live.

I do not say this because I oppose capital punishment. In fact, I'd like to set aside the question about whether or not one agrees with the death penalty. Assume that it is the law of the land and that it is applicable to murderers and their cohorts.

Under that assumption Moussaoui fits the bill for the death penalty. He was equally culpable for the deaths of thousands of Americans on September 11, 2001 because he had intimate knowledge of the plans and supported them rather than report them.

Moussaoui's conduct at trial clearly demonstrates that he has absolutely no remorse regarding the felling of the Twin Towers in New York or part of the Pentagon. In fact, he would like to see more deaths to Americans. He has made comments like "burn them all" and called his defense "American B.S." He smiles at the panicked 911 calls from September 11.

At first my reaction was that Moussaoui had lost it. Certainly that's what this week's spate of psychologists are suggesting in an attempt to spare his life. However, I now think he's "crazy like a fox." Moussaoui is simply a man deeply and completely dedicated to a form of radical Islam. Because of that Moussaoui wants to die. Moussoui believes that, as a Muslim matyr, he will be ushered into the presence of Allah. Whether or not seventy virgins are waiting for him there is beside the point: it is a guarantee of "salvation" in his mind.

And that's precisely why he should not die. Executing Moussaoui is a double-edged sword and both edges cut against the interests of this country. First, no justice would be served to Moussaoui because he would not be punished -- at least not in his perspective -- but would receive a reward. Second, the execution of Moussaoui would likely send tremors throw Muslims worldwide. Some might be incited to further violence. Others would be emboldened to commit acts that would merit a matyrs death either in their exercise or in their "punishment".

Let Moussaoui live out his days in a prison cell where he will eventually die as a cranky old man for having been denied a matyrs' death.

This page is powered by Blogger. Isn't yours?