Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a calender control and a grid view.
Now when i select the date in the calender control i want the records on that date will be displayed in that gridview can i do that?
Posted

Try this :

<asp:textbox id="TextBox1" runat="server" autopostback="True" xmlns:asp="#unknown">
       ontextchanged="TextBox1_TextChanged"></asp:textbox>


and code ...

protected void TextBox1_TextChanged(object sender, EventArgs e)
{
   // bind your gridview with the where clause of date 
}
 
Share this answer
 
Yes its very easy....

create stored procedure with following select statement

SQL
select * from tablename where Date=@Date



and pass your text box date as parameter from your code

i hope your understood...
 
Share this answer
 
v2
yes you can do it



XML
<div style="float:left;width:700px " >
     From Date &nbsp;
            <asp:TextBox ID="txtdate" BorderColor="#29447E" BorderStyle="Solid" BorderWidth="1px" width="110px" runat="server"  EnableTheming="False"></asp:TextBox>
                <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/Calender.jpg" Height="16px" Width="16px"
                    ImageAlign="TextTop" CausesValidation="False" />
                <asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txtdate" Enabled="True"  CssClass="blue" PopupPosition="BottomRight" PopupButtonID="ImageButton1" Format="dd-MMM-yyyy">
                </asp:CalendarExtender>
                     <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                        ErrorMessage="Please Choose Date" ControlToValidate="txtdate" Display="Dynamic" ForeColor="Red">
                    </asp:RequiredFieldValidator>

                 &nbsp;
    To Date &nbsp;
        <asp:TextBox ID="txttodate" BorderColor="#29447E" BorderStyle="Solid" BorderWidth="1px" width="110px" runat="server"  EnableTheming="False"></asp:TextBox>
                <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/Calender.jpg" Height="16px" Width="16px" ImageAlign="TextTop" CausesValidation="False" />
                <asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txttodate" Enabled="True"  CssClass="blue" PopupPosition="BottomRight" PopupButtonID="ImageButton2" Format="dd-MMM-yyyy">
                </asp:CalendarExtender>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2"
                        runat="server" ErrorMessage="Please Choose Date" ControlToValidate="txttodate" Display="Dynamic" ForeColor="Red">
                    </asp:RequiredFieldValidator>
                    &nbsp;&nbsp;
 <asp:Button ID="btnsubmit" runat="server" Text="View Report" CssClass="tab"
         onclick="btnsubmit_Click" />
       
</div>
<br /><br />
<asp:Panel ID="Panel1" runat="server" Width="800px" ScrollBars="Horizontal" style =" max-height:500px" >
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>

 <asp:GridView ID="GridView1" runat="server" AllowPaging="True" OnRowDataBound="GridView1_RowDataBound" PageSize="16" DataKeyNames="Cr_No" DataSourceID=&uot;SqlDataSource2" PagerSettings-FirstPageText="First" PagerSettings-LastPageText="Last" PagerSettings-Mode="NumericFirstLast">
                             
                                <PagerStyle CssClass="PagerStyle" />
                            <Columns>
                              <asp:TemplateField HeaderText="Cr Date">
                                <ItemTemplate>
                                    <asp:Label ID="crdate" runat="server" Text='<%# Bind("Cr_Dt","{0:dd-MMM-yyyy}") %>'></asp:Label>
                                </ItemTemplate>
  <ItemStyle HorizontalAlign="Center" Width="40px"  />
  <HeaderStyle CssClass="headerstylelist" HorizontalAlign="Center"  Width="40px" />
                         </asp:TemplateField>        
                                
                            </Columns>
                        </asp:GridView>
                    </ContentTemplate>
                        <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="btnsubmit"  EventName="Click" />
                        </Triggers>
    </asp:UpdatePanel>

                        <asp:SqlDataSource ID="SqlDataSource2" runat="server"
                            ConnectionString="<%$ ConnectionStrings:hospital %>"
                            SelectCommand="SELECT [Cr_No], [Cr_Dt] FROM [opdreport] WHERE (([Cr_Dt] >= @fromdate) AND ([Cr_Dt] <= @todate))"  >
                            <SelectParameters>
                              <asp:ControlParameter Name="fromdate" ControlID="txtdate" PropertyName="Text" Type="DateTime"     />
                                <asp:ControlParameter Name="todate" ControlID="txttodate" PropertyName="Text" Type="DateTime"     />
                            </SelectParameters>
                        </asp:SqlDataSource>
                         </asp:Panel>
 
Share this answer
 
v2
Comments
veenusethi 9-Feb-13 1:33am    
Or you can use also this if only one date is available

<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:hospital %>"
SelectCommand="SELECT [Cr_No], [Cr_Dt] FROM [opdreport] WHERE ([Cr_Dt] = @fromdate )" >
<SelectParameters>
<asp:ControlParameter Name="fromdate" ControlID="txtdate" PropertyName="Text" Type="DateTime" />

</SelectParameters>
at first take a textbox and add calender extender from ajax or use java script to add calender on it... and set textbox 's autopostback true and set textbox textchange event true...

like..
XML
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"
       ontextchanged="TextBox1_TextChanged"></asp:TextBox>


and write code for gridview here...


C#
protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }


using whare clase ....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900