What happens when you click on the header of a column to sort by?
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
NIthya Natha...
Member
6 Points
59 Posts
Sort gridview using "From" and "To" dates.
Apr 24, 2012 01:40 AM|LINK
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="IncomeReport.aspx.cs" Inherits="IncomeReport" EnableEventValidation="false"%> <!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></title> <script type="text/javascript" language="javascript"> function CallPrint() { var grid_ID = 'GridView1'; var grid_obj = document.getElementById(grid_ID); if (grid_obj != null) { var new_window = window.open(print.html); new_window.document.write(grid_obj.outerHTML); new_window.print(); new_window.close(); } } function winopen() { window.open("cal.aspx", "mywindow", "left=20, top=20, width=250, height=250, toolbar=0, resizable=0"); } </script> <script src="Scripts/CalendarControl.js" language="javascript" type="text/javascript"></script> <link href="Styles/CalendarControl.css" rel="Stylesheet" type="text/css" /> </head> <body> <form id="form1" runat="server"> <div> <table border="1"> <tr> <td> Department </td> <td> Cost Centre </td> <td> Month </td> <td> Amount </td> </tr> <tr> <td> <asp:DropDownList ID="ddlDept" DataSourceID="PopulateDept" AutoPostBack="true" DataValueField="dept_ID" DataTextField="dept_name" runat="server" AppendDataBoundItems="true"> <asp:ListItem Text="---Select A Department---" Value="default"></asp:ListItem> <asp:ListItem Text="All" Value="%"></asp:ListItem> </asp:DropDownList> <asp:SqlDataSource ID="PopulateDept" runat="server" ConnectionString="<%$ ConnectionStrings:MyConn %>" ProviderName="<%$ ConnectionStrings:MyConn.ProviderName %>" SelectCommand="SELECT DISTINCT [dept_ID], [dept_name] FROM [department]"></asp:SqlDataSource> </td> <td> <asp:DropDownList ID="ddlCC" AutoPostBack="true" DataValueField="cc_ID" DataTextField="costCentre_name" runat="server" AppendDataBoundItems="true"> <asp:ListItem Text="---Select A Cost Centre---" Value="default"></asp:ListItem> <asp:ListItem Text="All" Value="%"></asp:ListItem> </asp:DropDownList> </td> <td>From: <input id="from" name="from" onfocus="showCalendarControl(this)" type="text" /> To: <input id="to" name="to" onfocus="showCalendarControl(this)" type="text" /> </td> <td></td> </tr> <tr> <td colspan="4"> <br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowPaging="true" ShowFooter="true" AllowSorting="true" DataSourceID="dsGridView" PageSize="10" OnRowDataBound="GridView1_RowDataBound"> <Columns> <asp:BoundField DataField="dept_name" HeaderText="Department Name" SortExpression="dept_ID" /> <asp:BoundField DataField="costCentre_name" HeaderText="Cost Centre" SortExpression="cc_ID" /> <asp:BoundField DataField="month" HeaderText="Month" FooterText="<b>Total</b>" SortExpression="month" /> <asp:TemplateField HeaderText="Amount" SortExpression="amount"> <ItemTemplate> <asp:Label ID="lblTotal" runat="server" Text='<%# Eval("amount").ToString() %>'> </asp:Label> </ItemTemplate> <FooterTemplate> <asp:Label ID="lblTotal2" runat="server"></asp:Label> </FooterTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:SqlDataSource ID="dsGridView" runat="server" ConnectionString="<%$ ConnectionStrings:MyConn %>" ProviderName="<%$ ConnectionStrings:MyConn.ProviderName %>" SelectCommand="SELECT DISTINCT d.[dept_ID], d.[dept_name], c.[cc_ID], c.[costCentre_name], m.[month], m.[amount] FROM department d, costCentre c, monthlyIncome m WHERE d.dept_ID=c.dept_ID AND c.cc_ID=m.cc_ID" FilterExpression="Convert(dept_ID, 'System.String') like '{0}%' AND Convert(cc_ID, 'System.String') like '{1}%' AND ([month] Convert('from.Text', 'System.DateTime') AND Convert('to.Text', 'System.DateTime'))"> <FilterParameters> <asp:ControlParameter Name="dept_ID" ControlID="ddlDept" PropertyName="SelectedValue" /> <asp:ControlParameter Name="cc_ID" ControlID="ddlCC" PropertyName="SelectedValue" /> <asp:ControlParameter Name="month" ControlID="from" PropertyName="Text" /> <asp:ControlParameter Name="month" ControlID="to" PropertyName="Text" /> </FilterParameters> </asp:SqlDataSource> </td> </tr> </table> <input type="button" value="Print" id="btnPrint" runat="server" onclick="javascript:CallPrint()" /> OR Report Format:<asp:DropDownList ID="ddlReportFormat" runat="server"> <asp:ListItem Text="Please Select A Format" Value="default"></asp:ListItem> <asp:ListItem Text="Excel" Value="1"></asp:ListItem> <asp:ListItem Text="Word" Value="2"></asp:ListItem> <asp:ListItem Text="PDF" Value="3"></asp:ListItem> </asp:DropDownList> <asp:Button ID="repSel" runat="server" Text="Generate Report" OnClick="GenerateReport"/> </div> </form> </body> </html>Thanks in advance!
superguppie
All-Star
48225 Points
8679 Posts
Re: Sort gridview using "From" and "To" dates.
Apr 25, 2012 11:47 AM|LINK
What happens when you click on the header of a column to sort by?
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: Sort gridview using "From" and "To" dates.
Apr 26, 2012 08:14 AM|LINK
Hi,
Try the Calender control in server side. Or you can use Calender extender in Ajax.
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework