title: Display data from SQL based on date selected
body: <p>I'm new to ASP.NET
  I have a GridView that display data from SQL table.
  I want to display data in the GridView based on the date selected from either Calendar or Textbox.
  Here is the code:</p>
  
  <pre><code>&lt;p&gt;&lt;asp:Label ID="Date" runat="server"&gt;Select Date:&lt;/asp:Label&gt;
  
    &lt;asp:Calendar ID="Calendar2" runat="server"  SelectionMode="DayWeekMonth" onselectionchanged="Calendar1_SelectionChanged"&gt;
          &lt;/asp:Calendar&gt;
  
      &lt;p&gt;Todays Date is:  &lt;asp:Label ID="lblday" runat="server"&gt;&lt;/asp:Label&gt;&lt;/p&gt;
      &lt;p&gt;Selected Date is:&lt;asp:Label ID="lblbday" runat="server"&gt;&lt;/asp:Label&gt;&lt;/p&gt;
  
  &lt;asp:Button ID="addDates" runat="server" Text="Display" class="button1" 
          style="margin-left: 137px" Width="150px" /&gt;
      &lt;/p&gt;
  &lt;!--&lt;p&gt;&lt;asp:Calendar ID="drdates" runat="server" class="textbox1"&gt;&lt;/asp:Calendar&gt;--&gt;
  
  
      &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
          DataSourceID="SqlDataSource1" Height="178px" Width="402px"&gt;
          &lt;Columns&gt;
              &lt;asp:BoundField DataField="scode" HeaderText="scode" SortExpression="scode" /&gt;
              &lt;asp:BoundField DataField="drdates" HeaderText="drdates" 
                  SortExpression="drdates" /&gt;
              &lt;asp:BoundField DataField="Column1" HeaderText="Column1" ReadOnly="True" 
                  SortExpression="Column1" /&gt;
          &lt;/Columns&gt;
      &lt;/asp:GridView&gt;
      &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
          ConnectionString="&lt;%$ ConnectionStrings:AbcConnectionString %&gt;" 
          SelectCommand="select scode, drdates, count(*) from drreceive_20141229 group by drdates, scode"&gt;
      &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>Here is C# code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Data.SqlClient;
  
  namespace ISYSProject
  {
      public partial class _Default : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
  
          }
          protected void Calendar1_SelectionChanged(object sender, EventArgs e)
          {
              lblday.Text = Calendar2.TodaysDate.ToShortDateString();
              lblbday.Text = Calendar2.SelectedDate.ToShortDateString();
          }
      }
  }
  </code></pre>