Click here to Skip to main content
5,785,816 members and growing! (18,640 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate

GridView needs more plumbing code to support Calendar controls

By Viswanath Majeti

GridView needs more plumbing code to support Calendar controls
C# 2.0, C#, Windows, .NET, .NET 2.0, WebForms, ASP.NET, VS2005, Visual Studio, Dev

Posted: 27 Nov 2007
Updated: 27 Nov 2007
Views: 5,885
Bookmarked: 12 times
Note: This is an unedited reader contribution
Announcements
Loading...



Search    
Advanced Search
Sitemap
5 votes for this Article.
Popularity: 3.15 Rating: 4.50 out of 5
0 votes, 0.0%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
1 vote, 20.0%
4
4 votes, 80.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Download TaskManager.zip - 55.4 KB

GridView needs more plumbing code to support Calendar controls

Introduction

I needed to create a TaskManager application to manage tasks assigned to programmers in my team and used calendar controls to provide the StartDate and EndDate for each task created. I am able provide two way binding for SelectedDate and also retain the VisibleDate as documented on MSDN, but I had problems retaining the SelectedDate in the GridView during edits.

Background

Although I have EnableViewState set to True, I had to store the StartDate and EndDate in ViewState collection as ViewState ["StartDate"] and ViewState ["EndDate"] and assign them to SelectedDate during page refresh. The code to do this is straight forward and is shown below.

Screenshot - TaskManager.jpg

Using the Code

<code> 
protected void Page_Load(object sender, EventArgs e) 
{ 
    if (ViewState["StartDate"] != null) 
    { 
        ((Calendar)grdTaskManager.Rows[grdTaskManager.EditIndex].Cells[5].Controls[1]).SelectedDate = (DateTime)ViewState["StartDate"]; 
    } 
    if (ViewState["EndDate"] != null) 
    { 
        ((Calendar)grdTaskManager.Rows[grdTaskManager.EditIndex].Cells[6].Controls[1]).SelectedDate = (DateTime)ViewState["EndDate"]; 
    } 
} 
</code>
<code> 
protected void Calendar1_SelectionChanged(object sender, EventArgs e) 
{ 
    ViewState["StartDate"] = ((Calendar)grdTaskManager.Rows[grdTaskManager.EditIndex].Cells[5].Controls[1]).SelectedDate; 
} 
</code>
<code> 
protected void Calendar2_SelectionChanged(object sender, EventArgs e) 
{ 
    ViewState["EndDate"] = ((Calendar)grdTaskManager.Rows[grdTaskManager.EditIndex].Cells[6].Controls[1]).SelectedDate; 
} 
</code>
<code> 
protected void odsTaskManager_Updating(object sender, SqlDataSourceCommandEventArgs e) 
{ 
    if (ViewState["StartDate"] != null) 
    { 
        e.Command.Parameters["@StartDate"].Value = ((DateTime)ViewState["StartDate"]).ToString(); 
        ViewState.Remove("StartDate"); 
    } 
    if (ViewState["EndDate"] != null) 
    { 
        e.Command.Parameters["@EndDate"].Value = ((DateTime)ViewState["EndDate"]).ToString(); 
        ViewState.Remove("EndDate"); 
    } 
    if (txtTaskDescription.Text.Length >

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Viswanath Majeti


Viswanath Majeti works as a Project Lead in .NET Technologies for a software development company in Hyderabad, India
Occupation: Web Developer
Location: India India

Other popular ASP.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
  (Refresh) 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 27 Nov 2007
Editor:
Copyright 2007 by Viswanath Majeti
Everything else Copyright © CodeProject, 1999-2009
Web20 | Advertise on the Code Project