Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

Problem Setting GridView caption from Calendar1.SelectedDate

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Beowulf - 23 Jul 2007 20:26 GMT
I have a calendar control on a web form that I am using to allow users
to select which date to display a list of scheduled interviews.  The
SqlDataSource that is the datasource for the gridview has a
SelectParameter bound to Calendar1.SelectedDate.  This is all working
correctly.

The one thing I want to do seems simple enough, but I cannot get it to
work.  In Page_Load(), I want to set the caption of the GridView based
on the selected date on the calendar, but the code in Page_Load() is
always "one click behind".

On initial load of the page, Calendar1.SelectedDate is set to Now() and
the GridView displays the proper rows and the caption has today's date
in it.

The user clicks the date for this Thursday, and the GridView's rows are
properly updated to display the interviews for this Thursday, but in
Page_Load() when I try to set the GridView's caption,
Calendar1.SelectedDate is still set to today.

The user clicks the date for this Thursday again, and the GridView's
rows still display the interviewes for this Thursday, and now the
caption properly says "Scheduled interviews for 2007-Jul-26".

I'm sure there is something fundamental I'm missing here, but it seems
to me that the code in Page_Load() shouldn't be out of phase like this.
 Any assistance will be greatly appreciate.

ASPX page code:
<%@ Page Language="VB" MasterPageFile="~/Public/MasterPage.master"
AutoEventWireup="false" CodeFile="conduct_interviews.aspx.vb"
Inherits="Manage_conduct_interviews" title="Conduct - Candidate Phone
Interviews" theme="FABblue" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
  <span style="color: red; height: 13px">
    <br />
    <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
    <br />
    <asp:Literal ID="litErrMsg" runat="server"
    EnableViewState="False"></asp:Literal><br />
  </span>
  <br />
  <asp:GridView ID="gvwCandidateInterviews" runat="server"
AllowSorting="True" AutoGenerateColumns="False"
    DataSourceID="CandidateInterviewsDataSource" EmptyDataText="No
interviews scheduled for today." DataKeyNames="CandidateID,Slot_ID"
Caption="Phone Interviews Scheduled for Selected Date">
    <Columns>
      <asp:BoundField DataField="CandidateID" HeaderText="CandidateID"
InsertVisible="False" SortExpression="CandidateID" ReadOnly="True" />
      <asp:BoundField DataField="Slot_ID" HeaderText="Slot Num"
SortExpression="Slot_ID" ReadOnly="True" />
      <asp:BoundField DataField="CandidateRefID" HeaderText="Reference
ID" SortExpression="CandidateRefID" ReadOnly="True" />
      <asp:BoundField DataField="fname" HeaderText="First Name"
SortExpression="fname" ReadOnly="True" />
      <asp:BoundField DataField="lname" HeaderText="Last Name"
SortExpression="lname" ReadOnly="True" />
      <asp:BoundField DataField="dayphone" HeaderText="Day Phone"
SortExpression="dayphone" ReadOnly="True" />
      <asp:BoundField DataField="evephone" HeaderText="Eve Phone"
SortExpression="evephone" ReadOnly="True" />
      <asp:BoundField DataField="Cell Phone" HeaderText="Cell Phone"
SortExpression="Cell Phone" ReadOnly="True" />
      <asp:BoundField DataField="SlotDate" HeaderText="Slot Date/Time"
SortExpression="SlotDate" ReadOnly="True" />
      <asp:BoundField DataField="AssignedTo" HeaderText="Assigned To"
SortExpression="AssignedTo" ReadOnly="True" />
      <asp:BoundField DataField="Status" HeaderText="Status"
SortExpression="Status" />
      <asp:BoundField DataField="CheckedOutTo" HeaderText="Checked Out
To" SortExpression="CheckedOutTo" />
      <asp:CommandField ShowEditButton="True" ShowSelectButton="True"
SelectText="CheckOut" />
    </Columns>
  </asp:GridView>
  <br />
  <asp:SqlDataSource ID="CandidateInterviewsDataSource" runat="server"
    ConnectionString="<%$ ConnectionStrings:TrcStaff_Connection %>"
    SelectCommand="SELECT dbo.Candidates.CandidateID,
dbo.Candidates.CandidateRefID, &#13;&#10;  dbo.Candidates.fname,
dbo.Candidates.lname, &#13;&#10;  dbo.Candidates.dayphone,
dbo.Candidates.evephone, dbo.Candidates.[Cell Phone], &#13;&#10;
dbo.CandidateInterviews.Slot_ID, dbo.CandidateInterviews.Status,
dbo.CandidateInterviews.CheckedOutTo, &#13;&#10;
dbo.CandidateSlots.SlotDate, dbo.CandidateSlots.AssignedTo
&#13;&#10;FROM dbo.Candidates INNER JOIN dbo.CandidateInterviews
&#13;&#10;  ON dbo.Candidates.CandidateID =
dbo.CandidateInterviews.CandidateID &#13;&#10;INNER JOIN
dbo.CandidateSlots &#13;&#10;  ON dbo.CandidateInterviews.Slot_ID =
dbo.CandidateSlots.Slot_ID&#13;&#10;WHERE CONVERT(nvarchar(10),
SlotDate, 120) = @SelectedDate"
    UpdateCommand="UPDATE CandidateInterviews&#13;&#10;SET Status =
@Status, CheckedOutTo=@CheckedOutTo&#13;&#10;WHERE CandidateID =
@old_CandidateID&#13;&#10;AND Slot_ID = @old_Slot_ID&#13;&#10;AND
((Status Is Null) OR (Status = 'Checked Out'))"
    OldValuesParameterFormatString="old_{0}">
    <SelectParameters>
      <asp:ControlParameter ControlID="Calendar1" Name="SelectedDate"
PropertyName="SelectedDate" />
    </SelectParameters>
    <UpdateParameters>
      <asp:Parameter Name="Status" />
      <asp:Parameter Name="CheckedOutTo" />
      <asp:Parameter Name="old_CandidateID" />
      <asp:Parameter Name="old_Slot_ID" />
    </UpdateParameters>
  </asp:SqlDataSource>
</asp:Content>

ASPX code behind page:

Partial Class Manage_conduct_interviews
  Inherits System.Web.UI.Page

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
    With Me

      ' Default to today's date if user hasn't done anything yet
      If Not .IsPostBack Then
        .Calendar1.SelectedDate = Now()
        .Calendar1.VisibleDate = Now()
      End If

      ' Update caption to reflect selected date
      .gvwCandidateInterviews.Caption = "Phone Interviews Scheduled for
" & Format(Me.Calendar1.SelectedDate, "yyyy-MMM-dd")
    End With
  End Sub
Sergey Poberezovskiy - 24 Jul 2007 06:24 GMT
Move your Grid caption assigning logic into Page_PreRender event - it happens
just before the page is rendered, but AFTER all controls' postback events
(like clicks, index changes, etc)

> I have a calendar control on a web form that I am using to allow users
> to select which date to display a list of scheduled interviews.  The
[quoted text clipped - 78 lines]
>      SelectCommand="SELECT dbo.Candidates.CandidateID,
> dbo.Candidates.CandidateRefID,
 dbo.Candidates.fname,
> dbo.Candidates.lname,
 dbo.Candidates.dayphone,
> dbo.Candidates.evephone, dbo.Candidates.[Cell Phone],

> dbo.CandidateInterviews.Slot_ID, dbo.CandidateInterviews.Status,
> dbo.CandidateInterviews.CheckedOutTo,

> dbo.CandidateSlots.SlotDate, dbo.CandidateSlots.AssignedTo

FROM dbo.Candidates INNER JOIN dbo.CandidateInterviews

 ON dbo.Candidates.CandidateID =
> dbo.CandidateInterviews.CandidateID
INNER JOIN
> dbo.CandidateSlots
 ON dbo.CandidateInterviews.Slot_ID =
> dbo.CandidateSlots.Slot_ID
WHERE CONVERT(nvarchar(10),
> SlotDate, 120) = @SelectedDate"
>      UpdateCommand="UPDATE CandidateInterviews
SET Status =
> @Status, CheckedOutTo=@CheckedOutTo
WHERE CandidateID =
> @old_CandidateID
AND Slot_ID = @old_Slot_ID
AND
> ((Status Is Null) OR (Status = 'Checked Out'))"
>      OldValuesParameterFormatString="old_{0}">
[quoted text clipped - 31 lines]
>      End With
>    End Sub
Beowulf - 24 Jul 2007 14:49 GMT
That did it.  Thanks for the pointer, Sergey!

> Move your Grid caption assigning logic into Page_PreRender event - it happens
> just before the page is rendered, but AFTER all controls' postback events
[quoted text clipped - 143 lines]
>>      End With
>>    End Sub

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.