• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 465
  • Last Modified:

SqlDatasource in asp.net

Create a report that should show record between the two dates select by user from the eworld popup calender.
i create two methods:
FirstDate()
SecondDate()
each return date selected by user.
i want, On_page load ,sqldatasource select command query to include these two methods
so that the returned value from each will be the date to be read.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.UI.WebControls;




namespace GambiaStat
{


    public partial class Showrejected : System.Web.UI.Page
    {

        private string Querystring = " ";
   


        protected void Page_Load(object sender, EventArgs e)
        {
       


           
            
        }

        private  DateTime FirstDate()
        {
            return period1.SelectedDate;

        }
        private DateTime SecondDate()
        {
            return period2.SelectedDate;
        }

        //private SqlDataSource  showreport()
        //{

            
        //}
        


        

        
        
        
      }









       



















    
}

Open in new window

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Showrejected.aspx.cs" Inherits="GambiaStat.Showrejected" %>
<%@ Register Assembly ="eWorld.UI, Version=2.0.6.2393, Culture=neutral, PublicKeyToken=24d65337282035f2" namespace="eWorld.UI" tagprefix="ew" %> 
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>
   
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "System.Data.SqlClient" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
                     <title>Overview of Rejected Applicants</title>
                 

                      <script type = "text/css">
          p {border-style:double; border-width:thick;border-color: ActiveBorder;}
          img1{float:left}
          img1{float:left}
          p {text-align:center; font-size:24pt;color:white;background-color:Maroon;
            width: 1020px;
            margin-left: 4px;}
        
        </script> 
           
                     <style type="text/css">
                         .style2
                         {
                             width: 74px;
                         }
                         .style4
                         {
                             width: 273px;
                         }
                         .style5
                         {
                             width: 211px;
                         }
                     </style>
           
</head>
<body>
    <form id="form1" runat="server">
      
    <div>
         <table>
                    <tr><td valign= "top"><img src = "statistics.gif"  style= "width:200px; height:100px"/></td></tr>
                            
          </table>        
            
              <p style="color: #008080; text-decoration: underline; font-size: x-large; text-transform: uppercase; font-variant: small-caps; font-style: inherit; font-weight: bold; font-family: 'Times New Roman', Times, serif"> STATISTIC OF REJECTED APPLICANTS PER STATION:</p>
              <h1 style="border-style: solid; background-color: #800000; font-family: 'Copperplate Gothic Bold'; font-size: medium; font-weight: normal; font-style: inherit; font-variant: small-caps; text-transform: uppercase; color: #FFFFFF; width: 944px;">Station and Time Period:</h1>
            
   
    </div>
    <div>
    <table border ="1"   style="width: 720px">
       <%-- <tr>
        <td class="style2"  align="left">
            <asp:DropDownList ID="DropDownList1" runat="server" Width="131px" Height="22px">
           
            <asp:ListItem>BJL</asp:ListItem>
            <asp:ListItem>BK</asp:ListItem>
            <asp:ListItem>BS</asp:ListItem>
            <asp:ListItem >FF</asp:ListItem>
            <asp:ListItem>SK</asp:ListItem>
            <asp:ListItem>ALL</asp:ListItem>
            <asp:ListItem Selected="True">STATION:</asp:ListItem>
                
            </asp:DropDownList>
            
        </td>
        </tr>--%>
      <tr>
      <td><asp:Label ID="Label1" runat="server" Text="STARTDATE:" ForeColor="Maroon"></asp:Label>
      </td>

        
      
        <td class="style5">
        <ew:CalendarPopup runat="server" id="period1" Nullable="True" ShowGoToToday="True" 
                PopupLocation="Bottom"/> 
        </td> 
        <td> <asp:Label ID="Label2" runat="server" Text="ENDDATE:" ForeColor="Maroon"></asp:Label>
        </td> 
        <td class="style4">
        <ew:CalendarPopup runat = "server" ID ="period2" Nullable="true" ShowGoToToday="true"
        PopupLocation ="Bottom"> </ew:CalendarPopup>
        </td>  
        
        
        
        </tr>
      
    
        
     
         
         
        
         </table>  
         </div>

                <div>

     
        
       <asp:GridView ID="GridView1"  AutoGenerateColumns="False" runat="server" Width="957px" 
                        BackColor="#DEBA84" BorderStyle="None" Font-Bold="True" 
                        CaptionAlign="Top" BorderColor="#DEBA84" BorderWidth="1px" CellPadding="3" 
                        CellSpacing="2" SelectedIndex="1" DataSourceID="SqlDataSource1">
       
       <Columns>
       <asp:BoundField HeaderText="Nationality" DataField="Nationality" 
               SortExpression="Nationality" />
       <asp:BoundField HeaderText="Nin" DataField = "Nin" SortExpression="Nin"  />
       <asp:BoundField HeaderText="ApprovalStatus" DataField ="ApprovalStatus" 
               SortExpression="ApprovalStatus" />
           <asp:BoundField DataField="gender" HeaderText="gender" 
               SortExpression="gender" />
       </Columns>
           <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
           <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
           <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
           <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
           <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
           <SortedAscendingCellStyle BackColor="#FFF1D4" />
           <SortedAscendingHeaderStyle BackColor="#B95C30" />
           <SortedDescendingCellStyle BackColor="#F1E5CE" />
           <SortedDescendingHeaderStyle BackColor="#93451F" />
        </asp:GridView>
      


  




                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:IDKitConnectionString2 %>" SelectCommand="Select Nationality,Nin,ApprovalStatus,gender From Bio_data where DateCreated between 'FirstDate()'and 'SecondDate()' ">
                        </asp:SqlDataSource>
      


  




            </div> 
            
    </form>
</body>
</html>

Open in new window

0
Atouray
Asked:
Atouray
1 Solution
 
ddayx10Commented:
You probably want to use a controlparameter to get where you're going. I put up a simple sample of how this operates <see snippet>.

You can use this for further reference:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.controlparameter.aspx

Since you are using this calendar popup:
<ew:CalendarPopup runat="server" id="period1" Nullable="True" ShowGoToToday="True" PopupLocation="Bottom"/>

Your parameters would look something like this:
<asp:ControlParameter Name="FirstDate" ControlID="period1" PropertyName="SelectedDate" />
<asp:ControlParameter Name="SecondDate" ControlID="period2" PropertyName="SelectedDate" />

Your selectcommand would probably look something like this:
SelectCommand="Select Nationality,Nin,ApprovalStatus,gender From Bio_data where DateCreated between @FirstDate and @SecondDate'


Its either that or setting up normal sql parameters:
http://msdn.microsoft.com/en-us/library/z72eefad.aspx

Then you could set their values in the code behind to use the values from your calendarpopups
<div>
		<asp:Label ID="Period1" runat="server" Text="Daffy" />
	
		<asp:GridView ID="GrdView" runat="server" DataSourceID="SqlDS" />
		<asp:SqlDataSource ID="SqlDS" runat="server"
		 ConnectionString="Data Source=WT101\WT101A;Initial Catalog=WellNess;Integrated Security=True"
		 SelectCommand="SELECT * FROM WellnessChoice WHERE pi_fname=@FirstName">
		 <SelectParameters>
			<asp:ControlParameter Name="FirstName" ControlID="Period1" PropertyName="Text" />
		 </SelectParameters>
		 </asp:SqlDataSource>
    </div>

Open in new window

0
 
AtourayAuthor Commented:
thanks
that fine.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now