|
Rank: Advanced Member Groups: Member
Joined: 8/25/2007 Posts: 34
|
Hi,
I purchased your controls a month or two ago for use with my website, I was elated to learn that I got a new datepicker - and mistakenly replaced all of my old datepickers prior to testing it thoroughly. So now I have at least a dozen datepicker controls not working properly. When I attempt to access SelectedDateString I get the following error:
Unable to cast object of type 'System.String' to type 'EO.Web.DateCollection'.
I have a page that loads the process prior to loading the page which seems to be the cause, I can access these properties perfectly if I do so AFTER the first page load.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi Versile,
Please post the complete stack trace of the error message and related code that triggers the error.
Thanks
|
|
Rank: Advanced Member Groups: Member
Joined: 8/25/2007 Posts: 34
|
Full Page Code
Code: C#
public partial class Managers_clockin_graph : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
start_dpicker.SelectedDate = DateTime.Now.AddDays(-8);
end_dpicker.SelectedDate = DateTime.Now.AddDays(-1);
}
}
protected void BuildIt(ZedGraph.Web.ZedGraphWeb webObject, System.Drawing.Graphics g, ZedGraph.MasterPane pane)
{
pane.PaneList.Clear();
pane.Fill.Color = System.Drawing.Color.White;
GraphPane mypane = new GraphPane();
mypane.Title.Text = "IVR Clock-In's by Office\nLast Seven Days";
//mypane.XAxis.Title.Text = "Team"
//mypane.YAxis.Title.Text = "Total Jobs"
mypane.XAxis.Type = AxisType.Text;
mypane.XAxis.MinorTic.IsInside = true;
mypane.XAxis.MajorTic.IsBetweenLabels = true;
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(southernstar.ssi.connection());
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("stv_graph_ivr_byofc", conn);
cmd.CommandType = CommandType.StoredProcedure;
[size=8][color=brown] string xx = start_dpicker.SelectedDateString;
string yy = end_dpicker.SelectedDate.ToShortDateString();
cmd.Parameters.AddWithValue("@start", xx);
cmd.Parameters.AddWithValue("@end", yy);[/color][/size]
System.Data.DataTable objtb = new System.Data.DataTable();
try
{
conn.Open();
System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter(cmd);
adapter.Fill(objtb);
conn.Close();
}
catch (Exception ex)
{
string xyz = ex.Message;
conn.Close();
}
string[] str = { "0" };
double[] x = { 0 };
double[] y = { 0 };
double[] z = { 0 };
Array.Resize(ref x, objtb.Rows.Count);
Array.Resize(ref y, objtb.Rows.Count);
Array.Resize(ref str, objtb.Rows.Count);
Array.Resize(ref z, objtb.Rows.Count);
for (int i = 0; i <= objtb.Rows.Count - 1; i++)
{
System.Data.DataRow row = objtb.Rows[i];
str.SetValue(row["locshort"].ToString(), i);
x.SetValue(double.Parse(row["clockins"].ToString()), i);
y.SetValue(double.Parse(row["jobs"].ToString()), i);
z.SetValue(double.Parse("0"), i);
}
BarItem mycurve1 = mypane.AddBar("Clockins", z, x, System.Drawing.Color.Green);
BarItem mycurve2 = mypane.AddBar("Jobs", z, y, System.Drawing.Color.Red);
mypane.XAxis.Scale.TextLabels = str;
mypane.XAxis.MajorTic.IsBetweenLabels = true;
pane.Add(mypane);
pane.AxisChange(g);
mypane.YAxis.Scale.Max += mypane.YAxis.Scale.MajorStep;
BarItem.CreateBarLabels(mypane, true, "F0");
}
}
Stack Trace System.InvalidCastException was unhandled by user code Message="Unable to cast object of type 'System.String' to type 'EO.Web.DateCollection'." Source="EO.Web" StackTrace: at EO.Web.Calendar.get_SelectedDates() at EO.Web.Calendar.get_SelectedDate() at EO.Web.Calendar.get_SelectedDateString() at Managers_clockin_graph.BuildIt(ZedGraphWeb webObject, Graphics g, MasterPane pane) in c:\Documents and Settings\versile.SSI\Desktop\SSI_Web\Managers\clockin_graph.aspx.cs:line 40 at ZedGraph.Web.ZedGraphWeb.OnDrawPane(Graphics g, MasterPane mp) at ZedGraph.Web.ZedGraphWeb.CreateGraph(Stream OutputStream, ImageFormat Format, Boolean bShowTransparency) at ZedGraph.Web.ZedGraphWeb.Render(HtmlTextWriter output)
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
You can not access the Calendar's SelectedDateString property after it is rendered. Once the calendar is already rendered, it's considered to have already finished its mission and its state data becomes unusable. Try to access SelectedDateString before render and it should give you the correct value without problem.
Thanks
|
|
Rank: Advanced Member Groups: Member
Joined: 8/25/2007 Posts: 34
|
ok - I got it working using hiddenfields, I must have messed it up the first time I tried it.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
I am not sure if I get your question correctly: How to get a value inside Page_Load and pass it some other control to be used during its Render method. If that is the question, then there are many ways to do it. One of the easiest is to create a member/property on that control and then assign whatever value to that property during Page_Load. This is a very commonly used code techniques that has nothing to do with our product.
I am not sure what you mean by "GMDatePicker accomplished this?". Each controls have their own way of doing things, so sometimes you do need to change your code to accommodate when you switch to a new product.
|
|
Rank: Advanced Member Groups: Member
Joined: 8/25/2007 Posts: 34
|
It's fine now - I got it to work, I'm still sort of confused - but your explanation makes sense to me (now). For some reason when I tried to modify the code to use hiddenfields (which is what I would normally do) it failed similarly. I tried again and it is working perfectly. And yes this is true, and this datepicker is much cleaner than the other and bundled with other tools :)
|
|