I have page1.aspx with a calender control with multiple selection of dates with confirmation button below calender which displays selected dates in grid view below. Everthing worrking fine upto now.

Now i want to send the gridview data to nextpage.aspx using session.

Please see below code for gridview to display dates.

<asp:UpdatePanel ID="updpnl" runat="server">
        <asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="black"
            BorderWidth="1px" Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" Height="150px"
            NextPrevFormat="FullMonth" OnPreRender="Calendar1_PreRender" Width="200px" 
            OnSelectionChanged="Calendar1_SelectionChanged" SelectedDate="2012-07-18">
            <DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
            <NextPrevStyle Font-Bold="True" Font-Size="7pt" ForeColor="#333333" VerticalAlign="Bottom" />
            <OtherMonthDayStyle ForeColor="#999999" />
            <SelectedDayStyle BackColor="#333399" ForeColor="White" />
            <TitleStyle BackColor="White" BorderColor="Black"  Font-Bold="True"
                Font-Size="10pt" ForeColor="#333399" BorderWidth="1px" />
        <br />
        <asp:Label ID="lblErrorMessage" runat="server" Text="Label" Visible="False" 
            Font-Size="14px" ForeColor="Red"></asp:Label>
</asp:UpdatePanel><br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
        <asp:Button ID="btnDisplaySelectedDates" runat="server" Text="Confirm Selected Dates" 
            OnClick="btnDisplaySelectedDates_Click" />
        <asp:Button ID="btnClearSelection" runat="server" Text="Clear" OnClick="btnClearSelection_Click" />
<asp:UpdatePanel ID="up1" runat="server">
        <asp:GridView ID="GridView1" Font-Names="Verdana" Font-Size="Small" 
            runat="server" Width="200px"
            EmptyDataText="Select Dates and Confirm" CellPadding="4" AutoGenerateColumns="False"
            ForeColor="#333333" GridLines="None">
            <AlternatingRowStyle BackColor="White" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#EFF3FB" />
                <asp:TemplateField HeaderText="Selected Date" ItemStyle-HorizontalAlign="Right">
                        <%# DateTime.Parse(Container.DataItem.ToString()).ToShortDateString() %>
         <br />Select Number of People<asp:DropDownList ID="ddlNumberOfPeopleSwimming" runat="server" 
    onselectedindexchanged="ddl_SelectedIndexChanged" AutoPostBack="true"  
<br />Total in NZD:
<asp:Label ID="lblTotal" runat="server" ForeColor="Red" Font-Size="20px" ></asp:Label>
<asp:TextBox ID="txtnod" runat="server" AutoPostBack="True" BackColor="Red" 

        <br />

  <asp:Button ID="btnAccommodation" runat="server" Text="Select Accommodation" 
      BackColor="#7A1616" ForeColor="White" onclick="btnAccommodation_Click" 
      PostBackUrl="~/accommodation.aspx" />

Recommended Answers

All 3 Replies

Depending on how your btnDisplaySelectedDates function works that would probably be the best place to add your data to the session as well as adding it to the gridview. You can add them all to an array and store the array in session.
I noticed the NZD dollar amount too. Hello from a fellow kiwi:)

I noticed the NZD dollar amount too

Hi Steve,

Thanks very much for the reply (NZD) yeah i am from Auckland.
I tried using datatable and session.

Under btnDisplaySelectedDates

DataTable dt = (DataTable)GridView1.DataSource;
Session["data"] = dt;

and in next page;

DataTable dt = (DataTable)Session["data"];
GridView1.DataSource = dt;

and my gridview in nextpage is:

<asp:GridView ID="GridView1" Font-Names="Verdana" Font-Size="Small" runat="server" Width="240px"
                EmptyDataText="Select Dates and Confirm" CellPadding="4" AutoGenerateColumns="false"
                ForeColor="#333333" GridLines="None">
                <AlternatingRowStyle BackColor="White" ></AlternatingRowStyle>
                <HeaderStyle BackColor="#f3f3f3" Font-Bold="True" ForeColor="#363636" ></HeaderStyle>
                <RowStyle BackColor="#EFF3FB" ></RowStyle>
                    <asp:TemplateField HeaderText="Selected Date" ItemStyle-HorizontalAlign="Right"><ItemTemplate></ItemTemplate></asp:TemplateField>

But the selected dates are not transfering to next page.

Please could you see the code and let me know if i have done any mistake.


The probem maybe when you set the dt equal to Gridview.Datasource. After that line check the count of the rows of the dt and make sure it has something in it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.