DataSource Controls :: Filter - Select Date In Ddl And Use Selectedvalue In Gridview SelectCommand
Nov 7, 2010
I've got a gridview which works fine. I use dropdownlists which are filled with distinct values of the columns. So when I select an item in a drompdownlist the gridview refreshes based on the selected value. When I have a column which uses string values, I can start the filter with a default % value to use in my select paramaters. But when I have a date column, I can't use that. I use a datasource for the gridview and I prefer to leave codebehind out if this is not needed. Now I use >= in my gridview select to show all rows. but I want to use only = to make the filter work correct when I select a date in the ddl and use the selectedvalue in the gridview selectCommand
<asp:DropDownList ID="ddlUpdateDatum" DataSourceID="dsPopulateUpdateDatum"
AutoPostBack="true" DataValueField="UPDATEDATE" runat="server"
<asp:ListItem Text="All" Value="01/01/1900"></asp:ListItem>
<asp:SqlDataSource ID="dsPopulateUpdateDatum" runat="server"
ConnectionString="<%$ ConnectionStrings:GAMSYSTEMSqlServer %>"
SelectCommand="SELECT DISTINCT(UPDATEDATE) FROM [messages] ORDER BY UPDATEDATE ASC ">
And I use this in the gridview datasource:
ConnectionString="<%$ ConnectionStrings:DBSqlServer %>"
SelectCommand = "SELECT * FROM [messages] WHERE AND UpdateDatum >= @UpdateDatePar ORDER BY UpdateDatumDESC"
<asp:ControlParameter Name="UpdateDatePar" ControlID="ddlUpdateDate" PropertyName="SelectedValue" Type="string" />
i have a tablewhere datas are inserted and there is a colum foor inserting date on which data are inserted , so thatcolumn has datatype datetime and in design i have teo textbox one takes value for from date and the other for to date. on submit button click i want to display the datas between two dates. so i converted textbox value to datetime and it is showing data but the problem is suppose i inserted data on 29/04/2014 .now i want to view data inserted between 28/04/2014 and 29/04/2014 it doe not show any data but when i check between 29/--/-- and 30/--/-- i t display the data
In my access datasource, I have set the selectcommand to what the user desires via a DDL. So the user chooses say, all names beginning with "B". But as soon as user clicks to page to the next page, the filter is gone. What is the way to preserve the filter. I have only merely rebound the gridview in the Pageindexchanging event which obviously is not doing the trick. Does this call for a session var to hold the users choice?
How to filter Max or min value from gridview data which is bind with sql datasource.
Like I give date range from and to all the data popup in gridview then I have dropdown with 2 values Max and Min. If i select max so max value from payment column gridview shows and if I select min so min values from payment column shows.
a user will choose a period of time (from this date to this date) with a calendar ,, and then i want to get from DB all Invoices that were created within this period ??
each Invoice has a Date saved in Database..
This is the sql select statement i am using:
SelectCommand="SELECT [invoiceid] FROM [invoices] WHERE (([location] = @location) AND ([name] = @name)) AND date BETWEEN '"+ (fromdate.SelectedDate.ToShortDateString()) +"' AND '" + (todate.SelectedDate.ToShortDateString()) + "'">
i am getting this error message:
System.Data.SqlClient.SqlException: Conversion failed when converting date and/or time from character string.
I am trying to pass a variable within a selectcommand statment in ASP.NET and I have researched online how to do it but I can't seem to find a way to do it...What I am trying to do is write a code for a web page that will display a page with useful links on it where the links are separated into different topics and where everything is dynamically grabbed from a database. This is what I have so far: