That's the part I need help with....The SelectionChanged Event. I want to select only the due dates in the calendar and redirect to another page by populating data from another page. Please see my code below and help me in this matter ASAP.
Here's my code:
public partial class _Default : System.Web.UI.Page
I've put the pieces together on selecting days from calendar. Now I am trying to load selected date data into a form. For some reason, when I select a date from the calendar I am getting this date displayed
'01/01/0001'. Where is this coming from and what am I doing wrong or missing based on my code behind below? PLEASE HELP!!!
OracleConnection myConnection =
new
OracleConnection(ConfigurationManager.AppSettings["DSN"]);
OracleCommand myCommand =
new
OracleCommand("SELECT a.PROJECT_DUE FROM NEW_PROJECTS a WHERE upper(a.REPORTS_TO_ID) = '"
+ Session["UserName"].ToString() +
"'or lower(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString()
+ "' or upper(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString()
+ "'or lower(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString()
+ "'and a.proj_status = 'Active'", myConnection);
OracleDataReader dr;
myConnection.Open();
dr = myCommand.ExecuteReader();
while (dr.Read())
{
//assign the calendar control dates already contained in the database
Calendar1.SelectedDates.Add((DateTime)dr.GetOracleDateTime(0));
}
dr.Close();
myConnection.Close();
}
I think the date '01/01/0001' is displayed is by default, mean it is not bimding the control itself just debug the code lets see whether from DB date field is populating or not
Chetan Sarode
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
My date is not binding with database. Based on my code, how can I pass my due date so that it binds. Please look through my code and let me know where I am missing. Basically, I want to be able to select a due date and load that due date's data ONLY into
an edit form.
Calendar Render Function
protected void Calender1_DayRender(object
source, DayRenderEventArgs e)
{
// Declare the query string.
OracleConnection myConnection =
new
OracleConnection(ConfigurationManager.AppSettings["DSN"]);
OracleCommand myCommand =
new
OracleCommand("SELECT to_date(a.PROJECT_DUE,'MM-dd-yyyy') FROM NEW_PROJECTS a WHERE upper(a.REPORTS_TO_UTSWID)
= '" + Session["UserName"].ToString() +
"'or lower(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString()
+ "' or upper(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString()
+ "'or lower(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString()
+ "'and a.proj_status = 'Active'", myConnection);
OracleDataReader dr;
myConnection.Open();
dr = myCommand.ExecuteReader();
while (dr.Read())
{
//assign the calendar control dates already contained in the database
Calendar1.SelectedDates.Add((DateTime)dr.GetOracleDateTime(0));
}
dr.Close();
myConnection.Close();
}
chetan.sarod...
All-Star
65619 Points
11118 Posts
Re: Display user name in the header when logged in
Oct 20, 2009 03:27 AM|LINK
I guess you have already resolved the code for getting the user name
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
Cadeey
Member
102 Points
55 Posts
Re: Display user name in the header when logged in
Oct 20, 2009 07:54 PM|LINK
I did figured out getting the username, I need help with the calendar selection dates and redirecting to a new page.
chetan.sarod...
All-Star
65619 Points
11118 Posts
Re: Display user name in the header when logged in
Oct 21, 2009 03:15 AM|LINK
There is Selectionchnaged event for Calendar, you can get the selected date from it
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
Cadeey
Member
102 Points
55 Posts
Re: Display user name in the header when logged in
Oct 21, 2009 01:37 PM|LINK
Chetan-
That's the part I need help with....The SelectionChanged Event. I want to select only the due dates in the calendar and redirect to another page by populating data from another page. Please see my code below and help me in this matter ASAP.
Here's my code:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "Welcome, " + Session["UserName"].ToString();
BindData();
}
protected void BindData()
{
if (!IsPostBack)
{
if (Session["UserName"].ToString() != null)
{
string SessionName = Session["UserName"].ToString();
//Response.Write(Session["UserName"].ToString());
// Declare the query string.
OracleConnection myConnection = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);
OracleCommand myCommand = new OracleCommand("SELECT a.PROJECT_DUE FROM NEW_PROJECTS a WHERE upper(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString() + "'or lower(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString() + "' or upper(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString() + "'or lower(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString()+ "'and a.proj_status = 'Active'", myConnection);
myCommand.CommandType = CommandType.Text;
myConnection.Open();
OracleDataReader dr = myCommand.ExecuteReader();
while (dr.Read() == true)
{
//assign the calendar control dates already contained in the database
Calendar1.SelectedDates.Add((DateTime)dr.GetOracleDateTime(0));
}
dr.Close();
myConnection.Close();
}
}
}
protected void LoginStatus1_LoggingOut(object sender, LoginCancelEventArgs e)
{
FormsAuthentication.SignOut();
Response.Redirect("Login.aspx");
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
I NEED CODE THAT WILL ALLOW ME TO SELECT THE DUE DATES AND POPULATE DATA FROM NEW_PROJECT PAGE TO EDIT PAGE
}
Cadeey
Member
102 Points
55 Posts
Re: Display user name in the header when logged in
Oct 22, 2009 07:12 PM|LINK
Hi Chetan-
I found some code for my SelectionChanged event:
Protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
Response.Redirect("edit_project.aspx?PROJECT_DUE=" + (System.DateTime)Calendar1.SelectedDate);
System.DateTime d = default(System.DateTime);
//grab project due date
d = (System.DateTime)Request["PROJECT_DUE"];
}
However, I am getting this error message: Cannot convert type 'string' to 'System.DateTime'
Am I missing something???
chetan.sarod...
All-Star
65619 Points
11118 Posts
Re: Display user name in the header when logged in
Oct 26, 2009 03:33 AM|LINK
d = (System.DateTime)Request["PROJECT_DUE"].Tostring();
http://stackoverflow.com/questions/773284/cannot-convert-type-string-to-system-datetime
http://www.eggheadcafe.com/aspnet_answers/NETcsharp/May2006/post27411850.asp
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
Cadeey
Member
102 Points
55 Posts
Re: Display user name in the header when logged in
Oct 29, 2009 09:28 PM|LINK
Hi Chetan-
I've put the pieces together on selecting days from calendar. Now I am trying to load selected date data into a form. For some reason, when I select a date from the calendar I am getting this date displayed '01/01/0001'. Where is this coming from and what am I doing wrong or missing based on my code behind below? PLEASE HELP!!!
Calendar Render
protected void Calender1_DayRender(object sener, DayRenderEventArgs e)
{
// Declare the query string.
OracleConnection myConnection = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);
OracleCommand myCommand = new OracleCommand("SELECT a.PROJECT_DUE FROM NEW_PROJECTS a WHERE upper(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString() + "'or lower(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString() + "' or upper(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString() + "'or lower(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString() + "'and a.proj_status = 'Active'", myConnection);
OracleDataReader dr;
myConnection.Open();
dr = myCommand.ExecuteReader();
while (dr.Read())
{
//assign the calendar control dates already contained in the database
Calendar1.SelectedDates.Add((DateTime)dr.GetOracleDateTime(0));
}
dr.Close();
myConnection.Close();
}
Calendar Selection
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
foreach (DateTime SelectedDate in Calendar1.SelectedDates)
{
Response.Redirect("edit_project.aspx?PROJECT_DUE=" + Calendar1.SelectedDate.ToString("dd-MMM-yy"));
System.DateTime d = default(System.DateTime);
//grab project due date
d = DateTime.Parse(Request["PROJECT_DUE"]);
// LoadData();
}
}
Form Load
protected void LoadData()
{
//load data
OracleConnection objConn = new OracleConnection();
//string User_Name = User_Name.Substring;
//string Password = Password.Substring;
string strora = "SELECT PROJECT_NAME,PROJECT_DUE, REQUESTED_MANAGER, PROJ_DESCRIPTION, PROJ_CATEGORY, PROJ_STATUS, ASSIGNED_TO, PRIORITY_LEVEL FROM NEW_PROJECTS WHERE PROJECT_DUE = '" + Calendar1.SelectedDate.ToString("dd-MMM-yy") + "'";
objConn.ConnectionString = ConfigurationManager.AppSettings["DSN"];
OracleCommand objcmd = new OracleCommand(strora, objConn);
objcmd.CommandType = CommandType.Text;
objConn.Open();
OracleDataReader reader = objcmd.ExecuteReader();
reader.Read();
Response.Write(Calendar1.SelectedDate.ToLongDateString());
for (int x = 0; x < reader.FieldCount; x++)
{
// Response.Write("Project_Name");
//Response.Write(Project_Name.Text);
switch (reader.GetName(x).ToString())
{
case "PROJECT_NAME":
Project_Name.Text = reader.GetValue(x).ToString();
break;
case "PROJECT_DUE":
Project_Due.Text = reader.GetValue(x).ToString();
break;
case "REQUESTED_MANAGER":
Requested_Manager.Text = reader.GetValue(x).ToString();
break;
case "PROJ_DESCRIPTION":
Proj_Description.Text = reader.GetValue(x).ToString();
break;
case "PROJ_CATEGORY":
Proj_Category.Text = reader.GetValue(x).ToString();
break;
case "PROJ_STATUS":
Proj_Status.Text = reader.GetValue(x).ToString();
break;
case "ASSIGNED_TO":
Assigned_To.Text = reader.GetValue(x).ToString();
break;
case "PRIORITY_LEVEL":
Priority_Level.Text = reader.GetValue(x).ToString();
break;
}
}
objConn.Close();
}
chetan.sarod...
All-Star
65619 Points
11118 Posts
Re: Display user name in the header when logged in
Nov 03, 2009 02:07 AM|LINK
I think the date '01/01/0001' is displayed is by default, mean it is not bimding the control itself just debug the code lets see whether from DB date field is populating or not
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
Cadeey
Member
102 Points
55 Posts
Re: Display user name in the header when logged in
Nov 03, 2009 02:57 PM|LINK
My date is not binding with database. Based on my code, how can I pass my due date so that it binds. Please look through my code and let me know where I am missing. Basically, I want to be able to select a due date and load that due date's data ONLY into an edit form.
Calendar Render Function
protected void Calender1_DayRender(object source, DayRenderEventArgs e)
{
// Declare the query string.
OracleConnection myConnection = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);
OracleCommand myCommand = new OracleCommand("SELECT to_date(a.PROJECT_DUE,'MM-dd-yyyy') FROM NEW_PROJECTS a WHERE upper(a.REPORTS_TO_UTSWID) = '" + Session["UserName"].ToString() + "'or lower(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString() + "' or upper(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString() + "'or lower(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString() + "'and a.proj_status = 'Active'", myConnection);
OracleDataReader dr;
myConnection.Open();
dr = myCommand.ExecuteReader();
while (dr.Read())
{
//assign the calendar control dates already contained in the database
Calendar1.SelectedDates.Add((DateTime)dr.GetOracleDateTime(0));
}
dr.Close();
myConnection.Close();
}
Calendar SelectionChanged Function
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
Response.Redirect("edit_project.aspx?PROJECT_DUE=" + Calendar1.SelectedDate.ToString("MM/dd/yyyy"));
}
Form Load Function
protected void LoadData()
{
//load data
OracleConnection objConn = new OracleConnection();
// string User_Name = User_Name.Substring;
//string Password = Password.Substring;
// Response.Write(Calendar1.SelectedDate.ToString("MM/dd/yy"));
string strora = "SELECT PROJECT_NAME, REQUESTED_MANAGER, PROJ_DESCRIPTION, PROJ_CATEGORY, PROJ_STATUS, ASSIGNED_TO, PRIORITY_LEVEL FROM NEW_PROJECTS WHERE PROJECT_DUE = 'to_char(" + Calendar1.SelectedDate.ToString("MM/DD/yyyy") + ")'";
objConn.ConnectionString = ConfigurationManager.AppSettings["DSN"];
OracleCommand objcmd = new OracleCommand(strora, objConn);
objcmd.CommandType = CommandType.Text;
objConn.Open();
OracleDataReader reader = objcmd.ExecuteReader();
reader.Read();
//Response.Write(Calendar1.SelectedDate.ToString("MM/dd/yy"));
for (int x = 0; x < reader.FieldCount; x++)
{
//Response.Write("Project_Name");
// Response.Write(Project_Name.Text);
switch (reader.GetName(x).ToString())
{
case "PROJECT_NAME":
Project_Name.Text = reader.GetValue(x).ToString();
break;
case "PROJECT_DUE":
Project_Due.Text = reader.GetValue(x).ToString();
break;
case "REQUESTED_MANAGER":
Requested_Manager.SelectedValue = reader.GetValue(x).ToString();
break;
case "PROJ_DESCRIPTION":
Proj_Description.Text = reader.GetValue(x).ToString();
break;
case "PROJ_CATEGORY":
Proj_Category.SelectedValue = reader.GetValue(x).ToString();
break;
case "PROJ_STATUS":
Proj_Status.SelectedValue = reader.GetValue(x).ToString();
break;
case "ASSIGNED_TO":
Assigned_To.SelectedValue = reader.GetValue(x).ToString();
break;
case "PRIORITY_LEVEL":
Priority_Level.SelectedValue = reader.GetValue(x).ToString();
break;
}
}
objConn.Close();
}
chetan.sarod...
All-Star
65619 Points
11118 Posts
Re: Display user name in the header when logged in
Nov 04, 2009 02:00 AM|LINK
Will look into it
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.