January 17, 2006 at 4:59 am
Hi there
I am building a reporting tool in Asp.Net/c# - visual studio 2005. I have dropped a report viewer control onto one of my pages, and set it up for remote processing. This is being dynamically configured to point at different reports, depending on user selection, and for the most part, I am happy with how it is performing.
However, I am having trouble with reports that use Datetime parameters. Initially I found that the report would be rendered fine, with default date parameters being interpreted correctly as dd/mm/yyyy. However, whenever my reports included date parameters, the parameters toolbar would include a calendar picker icon alongside each date field. I would have expected that when clicking on this control, a calendar picker would appear and allow the user to select date inputs. Unfortunately, by clicking on this icon, the page load event appears to fire, and the report is run - as if the user had clicked view report.
I was unhappy with these unusable controls appearing on my page, so I changed the fields to string parameters. This has made the dormant calendar picker controls disappear, but now dates are being interpreted as mm/dd/yyyy, which is also highly undesirable, given the majority of the users will be UK-based. In reading up on this issue, some have suggested that the date format is determined by the regional settings on the client machine. I have ensured that the regional settings on both the web/reporting server and my client machine are English UK.
Preferably, I would love to know how to enable the calendar picker controls - is there some other event that I need to trap for? Otherwise, I would like to know how I can ensure that the string fields which are being used for datetimes will be interpreted as dd/mm/yyyy.
Thanks in advance!
Jesse Easton
January 18, 2006 at 1:43 am
Hi Jesse,
I think that the first problem:
I would have expected that when clicking on this control, a calendar picker would appear and allow the user to select date inputs. Unfortunately, by clicking on this icon, the page load event appears to fire, and the report is run - as if the user had clicked view report
is comming from your PostBack event on your Page_Load event. So I think when you click the icon you must first check if IsPostBack for example:
if(! IsPostBack)
{
you page load code here (for example initializing report parametsr or controls)
}
else
{
Reading other parameters or variables or make the Calender control ( datetime picker visible or other.
}
Then you can use the
private void Calendar1_SelectionChanged(object sender, System.EventArgs e) to put the selected date into the report parameter.
Your second problem,
....Preferably, I would love to know how to enable the calendar picker controls - is there some other event that I need to trap for? Otherwise, I would like to know how I can ensure that the string fields which are being used for datetimes will be interpreted as dd/mm/yyyy.
I think is in relation of the Globalization settings on the client machine.
System.Globalization have an CultureInfo class that allow you at run time to set (override the culture info)the culture info( en-US, nl-Nl and so one) and how to interpret your data.
An example of using is
At the top of your page (codebehind)
using System.Globalization;
private void Calendar1_SelectionChanged(object sender, System.EventArgs e)
{
//Set the culture info to represent the data in the browser
CultureInfo MyCultureInfo = new CultureInfo("nl-NL");
//CultureInfo USCultureInfo = new CultureInfo("en-US");
//CultureInfo UKCulture = new CultureInfo("en-GB"); and so one
//your @ReportParameter, I used a text box for a quick representation
this.txtDateTime.Text =
DateTime.Parse(this.Calendar1.SelectedDate.ToShortDateString(),
MyCultureInfo).ToShortDateString() ;
//But also you can use some of the other functions such as:
//this.Calendar1.SelectedDate.ToLongDateString() and so one...
}
Also look at:
there is a lot of information about formatting and cultureinfo
Kind regards,
Alexander Lilov
P.S. Let me know if all is OK
January 20, 2006 at 6:58 am
Hi Alexander
Thanks for taking the time to write such a comprehensive reply! I will give this a go and let you know how I get on.
Kind Regards
Jesse Easton
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply