Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 545
  • Last Modified:

How to define default day to Calendar control

Using the Calendar server control in a Detaillview and Formview and notice two issues.
1. Does not appear that current day is the defualt day selected. User has to select the day before the insert works. How can I define the current day as the default date selected? Currently I have to select the current day in the control before the insert will work.
2. I have a dropdown control in the detailview, and if the user selects a dropdown value other then the default value, selects a day in the calandar, the dropdown resets back to the default value.

I will next be looking up next how to validate dates selected by the user. I have two caladar controls, one for start date and one for ending date. So I will need to make sure the ending date is always later or equal to the starting date. I would like for the Ending date to always reset to the same date selected in the Starting date control. I think these deserve their own question.
0
Thirt
Asked:
Thirt
  • 4
  • 3
1 Solution
 
GRCHELPDESKCommented:
Hello Thirt,

You've been waiting for a while, so I'll try to help you with part of this.  

1) I believe you just need to set the selected date of the calendar in the page load event.

ex:
        If Not Page.IsPostBack Then
            Calendar1.SelectedDate = Now.Date
        End If

2) I'm not sure on this.  Silly question, are you binding the data to the dropdown control in the page load event?

Hope that helps,
GRCHELPDESK
0
 
ThirtAuthor Commented:
Thanks for replying! Good timing, got caught up in another fire.
1. It worked! Thanks.
2. Not sure if I understand your question, still new to VS. But I have a Dataview control, and in the Edit Template, I select InsertItem Template. There I have two sets of calandars that I want to capture a FROM and a TO date.

On a related note, I also need to BIND that data to a field that is also execpecting the time. So I need to bind the following format: dd/mm/yyyy hh:mm:ss am/pm

So I added new list fields to collect the time and am/pm from the user. But I have no idea now to take all 4 fields and bind to a single field.

Here's a snapshot of my data view in design mode, and showing the fields I'm trying build.
http://picasaweb.google.com/tomhirt/TroubleshootingCrap/photo#5100917782143773218

I guess I really don't need to display the actual date/time. Can I still bind it the date/time field?
0
 
GRCHELPDESKCommented:
Hey Thirt,

Ok, I think I understand now.  The employee selects their name, but when they select the date in the from calendar the employee dropdown reverts to the default value.  Let me know if I'm misunderstanding that.

I'm not 100% sure, but I think it's related to the calendar control.  You can set the auto-postback behaviour on most controls, but it's always set to true for the calendar control.  And it sounds to me like the postback from the calendar control is re-binding the data to the dropdown list, which naturally sets the value as the default value.

So, how are you binding the data to the dropdown list?  Are you doing it programatically?  If so set a break-point on the line when you bind the data to the dropdown list.  And check if it's firing on the postback from the calendar.

On a side note: If you're binding the data for that dropdown list in the Page_Load event, make sure it's contained between:

If Not Page.IsPostBack Then
  'Bind data here
End If

Let me know how that works out,
GRCHELPDESK
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
ThirtAuthor Commented:
Actually, the Employee Name and Resource Drop downs maintain their selected value after picking a date from the calander. It's that middle Dropdown called Type that gets reset to the default value when selecting a date from the calander control. They are all using the Bind(fieldname) option if that answers your question. I don't believe I'm doing this programically, as I'm a noob and just using the wizards. The only differnce between the three dropdowns is that the type dropdown is using a collection list, where the other two are using data sources.

How do I get to the On load event for the Dataview Insert Item template? Right now, I can just set the default date to the calander on the main page.

0
 
GRCHELPDESKCommented:
Fair enough.  I'll be honest, I never use wizards, slqDataSource objects, or anything like that so I'm not entirely sure how they work.  I tend to do everything programatically.  

But I had a thought about the dropdown using a collection.  I'll assume that means you've clicked the "items" property of the dropdown and manually created a collection of items for that dropdown list.  Each of these items you've added have a text property and a value property.  Are the value properties all unique?  The need to be.

To answer your question about getting to the load event for the detailsview object:

First double-click the details view object.  That'll bring up DetailsView1_PageIndexChanging event on the code behind screen.  In the top right you'll see a dropdown with a lightning bolt beside it.  Click it and select the load event.  (or whatever event you're looking for)
0
 
GRCHELPDESKCommented:
For funs sake, try modifying your existing Page_Load event like this:

        If Not Page.IsPostBack Then
            'Setup default calendar date
            Calendar1.SelectedDate = Now.Date

            'Setup DropDownList1 programatically
            DropDownList1.Items.Clear()
            DropDownList1.Items.Add(New ListItem("Item 1", "1"))
            DropDownList1.Items.Add(New ListItem("Item 2", "2"))
            DropDownList1.Items.Add(New ListItem("Item 3", "3"))

        End If

Then run it and see if it still changes to the default value.
0
 
ThirtAuthor Commented:
Sorry, forgot about this question. Found out that dumb dumb here assigned the same data value code it each of the dropdown values. So that's why it defualted back to the first item in the list. Doh!!! Thanks for your help, it got me past my problem.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now