Problem Setting GridView caption from Calendar1.SelectedDate


B

Beowulf

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,
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, [email protected]
WHERE CandidateID =
@old_CandidateID
AND Slot_ID = @old_Slot_ID
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
 
Ad

Advertisements

G

Guest

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)

Beowulf said:
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, 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, [email protected] WHERE CandidateID =
@old_CandidateID
AND Slot_ID = @old_Slot_ID
AND
 
Ad

Advertisements

B

Beowulf

That did it. Thanks for the pointer, Sergey!

Sergey said:
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)

Beowulf said:
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, 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, [email protected] WHERE CandidateID =
@old_CandidateID
AND Slot_ID = @old_Slot_ID
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top