Click here to Skip to main content
Click here to Skip to main content

GridView needs more plumbing code to support Calendar controls

, 27 Nov 2007
Rate this:
Please Sign up or sign in to vote.
GridView needs more plumbing code to support Calendar controls

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

Share

About the Author

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

Comments and Discussions

 
Questionhow to run the project?database file is missing Pinmemberbdmukta31-Aug-09 5:58 
hi
I just want to run the project..But I think data file named indotronix is missing.....can u give me any suggestion to run the project..
 
thanks

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.141022.2 | Last Updated 28 Nov 2007
Article Copyright 2007 by Viswanath Majeti
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid