Go Back   EN World D&D / RPG News > Blogs > Plane Sailing

Rate this Entry

ASP.Net Gotchas

Posted 25th July 2008 at 11:54 AM by Plane Sailing
Just jotting a few notes down here as I've resolved another annoying little asp.net 2.0 'gotcha', in this case relating to the calendar control.

I'm using a calendar control in a gridview when a row is in update mode. My database contains some null dates for 'PaperworkReceived', but the calendar control chokes on null dates so I transform them into 1/1/1900 dates so I can give them special programatic handling.

I'm connecting to an objectdatasource which provides my interface to the database.

When 'null' dates are present, I set the selected date to 1/1/1900, but I set the visible date to todays date so that the calendar is in the correct position for someone who wants to select the date if the paperwork has just been received.

The strange thing is that even if you obtain a reference to the calendar object in the _RowUpdating procedure and set the parameter to the value of the selected date, it still passes the current date to the objectdatasource (!).

I resolved this by checking in the _RowUpdating procedure and if the selectedDate is 1/1/1900 I programatically set the view date to that just before I assign the parameters. (I've also changed the Bind() to an Eval() in the gridview code).

Code:
DateTime defaultdate = new DateTime(1900, 1, 1);
Calendar c = (Calendar)gvAuditees.Rows[e.RowIndex].FindControl("calPaperwork");
if (c.SelectedDate == defaultdate) {
	c.VisibleDate = c.SelectedDate;
} 
ObjectDataSource2.UpdateParameters.Clear();
...
ObjectDataSource2.UpdateParameters.Add("PaperworkReceived", c.SelectedDate.ToLongDateString());


I also use ToLongDateString to ensure that SQL server reliably parses the date - otherwise I get faux US mmddyy conversions happening on some installations.

Cheers

Submit "ASP.Net Gotchas" to Digg Submit "ASP.Net Gotchas" to del.icio.us Submit "ASP.Net Gotchas" to StumbleUpon Submit "ASP.Net Gotchas" to Google
Posted in Uncategorized
Views 342 Comments 0
Total Comments 0

Comments

 
Total Trackbacks 0

Trackbacks

And yet another word from our sponsors
Visit Our Sponsors
Visit Our Sponsors... Again
Powered by vBadvanced CMPS v3.0.1

All times are GMT +1. The time now is 02:39 PM.


Site Contents © 2008 ENWorld
PHP Ajax Multimedia Web Framework © 2008 Digital Media Graphix
Powered by vBulletin® Version 3.8.0 Beta 1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

"Vault Data" powered by VaultWiki v2.5.1.
Copyright © 2008 - 2009, Cracked Egg Studios.