Welcome to Webhost4life Forum Sign in | Join | Faq

ASP.NET C#

Started by gstadter at 04-23-2008 7:49 AM. Topic has 1 replies.

Print Search
Sort Posts:    
   04-23-2008, 7:49 AM
gstadter is not online. Last active: 4/23/2008 10:41:31 PM gstadter

Not Ranked
Joined on 04-23-2008
Posts 1
conditionally set 'SelectedDate' value of Calendar from sqldatasource
Reply Quote
Arg.. Is there a way to do this?
I need to discover a way to evaluate the datetime value of the DueDate field prior to setting the SelectedDate value of the Calendar(in edit mode of a templatefield). If the value is null, I need to not set the proprty of the calendar at all. If the value is not null, then go ahead and set the SelectedDate property as equal to the value retrieved from the sqldatasource.
I've been scratching my head for a while on this one. ANY ideas or suggestions would be greatly appreciated.
Here are the applicable code (simple calendar("Calendar1") not shown:





string Username = CSContext.Current.User.Username;
void Page_Load()
{
TextBox1.Text = Username;
}


"
SelectCommand="SELECT [DueDate], [Priority], [ProjTitle], [Desc], [TaskID], [Title], [Status] FROM [ToDoItems] WHERE ([Owner] = @Owner) AND ([TaskID] = @TaskID)"
UpdateCommand="UPDATE [ToDoItems] SET [Priority] = @Priority, [ProjTitle] = @ProjTitle, [Title] = @Title, [Status] = @Status, [Desc] = @Desc, [DueDate] = @DueDate WHERE [TaskID] = @TaskID" OnSelected="Date_Select" >





Thank you!
,Gary
"We truly fail, only when we quit."

   Report 
   05-31-2008, 8:20 PM
tiredstudent is not online. Last active: 6/5/2008 9:49:41 PM tiredstudent

Top 100 Posts
Joined on 06-01-2008
Posts 3
Re: conditionally set 'SelectedDate' value of Calendar from sqldatasource
Reply Quote
@gstadter-

Would you be evaluating the DueDate field at on Page_Load or Row_DataBound (e.g. is this populating a IEnumerable such as a GridView or ListView)?   If on Page_Load, you'd need to have a method to go out and check the DueDate, then set the SelectedDate property of your calendar object.

Sample code, I haven't tried it in VS, just typing it out as pseudo code:

protected void Page_Load(object sender, EventArgs e)
{
  // data logic here to connect to your data source and business logic.
  DateTime dueDate = theDataRow["DueDate"] as DateTime;
  calendar1.SelectedDate = dueDate != null ? dueDate : null;  // notice: assuming .net 2.0 (datetime is nullable)
}


If this is done on RowDataBound or RowEditing (of a GridView) event, you could do something similar.

protected void MyGridView_RowEditingHandler (object sender, GridViewEditEventArgs e)
{
    // capture the current edit row and perform the same logic as in Page_Load.
}


If you could provide a bit more information on what type of TemplateField you're using (what type of control), that might help out. :)

Thanks!

-dl

   Report 
Webhost4life Fo... » General Discuss... » ASP.NET C# » conditionally set 'SelectedDate' value of Calendar from sqldatasource

Powered by Community Server, by Telligent Systems