Posted on 2011-11-01
Last Modified: 2012-05-12
I want my report to filter record base on user selection of the calender date.
On page load from CodeBehind file,
i want to check if both date are select then
conver the selected date to string format:YYYY-MM-DD ieuniversalshortableDateTimePattern
and assign to string date1 and date1
the date1 and date2 will be the filter crateria for my sql command query.
Question by:Atouray

    Author Comment


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Data.SqlClient;
    using System.Configuration;
    using eWorld.UI;
    using System.Web.UI.WebControls;
    namespace GambiaStat
        public partial class Showrejected : System.Web.UI.Page
            string  date1, date2;
            protected void Page_Load(object sender, EventArgs e)
                if (period1.SelectedDate && period2.SelectedDate)
                   // i want to  do assignments here ;

    Open in new window

    LVL 43

    Expert Comment

    So what is your question ?

    Author Comment


    <td class="style5">
            <ew:CalendarPopup runat="server" id="period1"  Nullable="True" ShowGoToToday="True" 
                    PopupLocation="Bottom" Culture="u"/> 
            <td> <asp:Label ID="Label2" runat="server" Text="ENDDATE:" ForeColor="Maroon"></asp:Label>
            <td class="style4">
            <ew:CalendarPopup runat = "server" ID ="period2" Nullable="true" ShowGoToToday="true"
            PopupLocation ="Bottom" AutoPostBack="True" Culture="u" > </ew:CalendarPopup>
            %-- <div>
                       <asp:GridView ID="GridView2" AutoGenerateColumns="False" runat="server" 
                              BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" 
                              CellPadding="4" DataSourceID="SqlDataSource2" Width="716px">
                               <asp:BoundField DataField="Nationality" HeaderText="Nationality" 
                                   SortExpression="Nationality" />
                               <asp:BoundField DataField="Nin" HeaderText="Nin" SortExpression="Nin" />
                               <asp:BoundField DataField="gender" HeaderText="gender" 
                                   SortExpression="gender" />
                               <asp:BoundField DataField="ApprovalStatus" HeaderText="ApprovalStatus" 
                                   SortExpression="ApprovalStatus" />
                           <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
                           <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
                           <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
                           <RowStyle BackColor="White" ForeColor="#003399" />
                           <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
                           <SortedAscendingCellStyle BackColor="#EDF6F6" />
                           <SortedAscendingHeaderStyle BackColor="#0D4AC4" />
                           <SortedDescendingCellStyle BackColor="#D6DFDF" />
                           <SortedDescendingHeaderStyle BackColor="#002876" />
                          <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                              ConnectionString="<%$ ConnectionStrings:IDKitConnectionString1 %>" 
                              SelectCommand="SELECT Nationality,Nin,gender,ApprovalStatus From Bio_data
                              where DateCreated between 'date1' and 'date2' and ApprovalStatus='Rejected'">

    Open in new window


    Author Comment

    how can i convert from DateTime to String in this format:
     YYYY-MM-DD ieuniversalshortableDateTimePattern
    LVL 43

    Accepted Solution

    String s = dte.ToString("YYYY-MM-DD");  //Look at DateTimeFormatInfo in help for description of the options
    LVL 43

    Expert Comment

    or possibly just
    String s = dte.ToString("u");
    which is universal date time (which has a time unlike your example you say you require which isn't actually a universal date time)
    LVL 43

    Expert Comment

    ps - dte is a DateTime object, replace it with whatever yours are called.

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    Title # Comments Views Activity
    Email Body 4 30
    C# - SOLID Question 6 35
    IIs block files web.config 6 45
    Path of Workbook 3 30
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now