Cannot get a RowFilter in a GridView control to work with a DateTime data type using a Dropdownlist as the filtering method

Hello,

 I have a DataView that I am using as the data source for a GridView control and when I add a DropDownList control into the header of any column type other than a DateTime type the filtering works fine on Postback from the dropdown.  I just cannot get it to work with a DateTime type.

 Here is a little bit of the code:

//Here's all the things I have tried: 

//Value is a string representation of my DateTime type (i.e. "12/01/2007 12:04:00 AM")

filter = propName + "=#" + Convert.ToDateTime(value) + "#";

filter = propName + "= ' " + value + " ' ";

filter = propName + "= # " + Convert.ToDateTime(value) + "#";

filter = String.Format(propName + "= #{0}#", Convert.ToDateTime(value));

filter = propName + " = #CONVERT(" + value + ",'System.DateTime')#";

CurrentDataView.RowFilter = filter;

FilterList.Add(filter);

 

I just cannot get any of these to work.  Can anyone help??

 

Thanks,

Ian

0
Ian
1/21/2008 9:09:26 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
1008 Views

Similar Articles

[PageSpeed] 10
Get it on Google Play
Get it on Apple App Store

Does the datetime have an actual time or is it dates with all the times set to 0 (midnight)? If it has times, equal likely won't work as you're thinking (everything on a given day). You need to either use BETWEEN or a combination of >= and <= depending on if you want inclusive times. Or you can do a datediff day =0 thing, but I'm not sure how that would work in a filter. I do it for actual queries because it performs best on our server.


Please Mark As Answer posts that helped you.

"If we learn from our mistakes, I should be brilliant by now."

0
nikki_doer_of_things
1/21/2008 10:31:13 PM

Your post was basically what the problem was.  I was getting in data into a DataView that was in System.DateTime format and then converting it to a string value for a dropdown value in a dropdown list.  Since DateTime values store precision beyond what we are seeing in the string value of the datetime value the match was never occuring.  I fixed it by converting all time values in the DateTime cells to 12:00:00 AM (also Uppercase on the AM/PM)

 

Thanks for the help,

Ian

0
Ian
1/22/2008 3:01:10 PM

Hi,

I have had the same problem myself and:

  • In Australia the month and day are reversed.
  • if you change to text comparison you have to be exact, and this might not happen between sql server and asp (eg 03 or 3)

The solution I found was the following:

1. Create a string with your date held in the variable dte ( this will set a time of 00:00:00:0000):

Dim strUS As String = String.Format("{0}/{1}/{2}", dte.Month.ToString, dte.Day.ToString, dte.Year)

2. Apply the filter (shiftDate is the SQL variable I am trying to sort on and has a time component of 00:00:00:0000):

tbl1.DefaultView.RowFilter = "ShiftDate = #" & strUS & "#"

3. Get the rows:

tbl2 = tbl1.DefaultView.ToTable

Remember to keep the time component as zero as you are comparing dates and not times.

RegardsBig Smile

0
SuperRoo
3/9/2009 1:29:24 AM
Reply:

Similar Artilces:

Trying to use the FAQ " Sorting and paging in the GridView control when not using data source controls "Sorting and paging in the GridView control when not using..."
and I am not getting the results I had hoped for.  I keep getting a "Compiler Error Message: CS0123: No overload for 'AdhocJobGridView_PageIndexChanged' matches delegate 'System.EventHandler'".   Here is my event handling... protected void AdhocJobGridView_PageIndexChanged(object sender, GridViewPageEventArgs e){ try { AdhocJobGridView.DataSource = wsBaseInfoArray; AdhocJobGridView.PageIndex = e.NewPageIndex; AdhocJobGridView.DataBind(); }catch (Exception ex) {throw ex; }   Here is my aspx... <asp:GridView ID="AdhocJobGridView...

using javascript getting value from textbox when edit button is clicked and both controls are present in gridview control
Hi All using javascript I want to get value  from textbox when edit button is clicked and both controls that is texbox and button are present in gridview control .Alok Hi aloksinha83, Please see this post: http://forums.asp.net/t/1069245.aspx Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

Issue with getting values from child controls in a gridview, to use for the update using a SQLDataSource control
Hi all, I have a gridview bound with a SQLDataSource. I am using the Update feature of the SQLDataSource to update a SQL Server database with values entered into the gridview. However I am not getting it to work. I believe this is due to the controls that contain the user entries are not the gridview itself, but rather child controls within the gridview. I have been using the names of the actual controls but nothing happens. Upon submit, the screen returns blank, and the database is not updated. Here is some code:   <asp:GridView ID="GridEditSettlement" runat="server" AutoGenerate...

BUG: Image Controls in UpdateProgess Control: Can not use FindControl() methods to get Image
There is a single UpdateProgress control on the page. as such: <ajax:UpdateProgress  ID="UpdateProgress1" runat="server"   DisplayAfter="100" >         <ProgressTemplate>                <div style="border:2px solid #0099FF; background-color:#EFEFEF; padding:10px; width:200px; height:20px;">               Updating Panel            </div&...

Getting the control id of a control inside gridview control
 uhmm.. a little bit confusing regarding my subject because i dont know how to say it...by the way my problem is how can i get the id of a control (e.g. textbox) inside the gridview... and the textbox is in the templatefield... is there any way i can get its id??  hoping i could get a reply as soon as possible... Regards,MhaeyPlease remember to click “Mark as Answer” on the post that helps you.. =) What do you want's to do by getting the id of the Text box? Do you want's to find particular Textbox with certain id ? Kamran ShahidSr. Software Engineer(MCP,MCAD.net,MC...

Using Data Control in another data control
Hey, How to use a SqlDataSource control in a GridView and so on...I mean i wanna show data which comes from UserTables in a gridview whoses data comes from ContentTable so they are two separated tables. Thanks and Regards...I am not a perfect programmer, but i have perfect programmers' habits [ i think so :)] I mean how to use nested gridview controls. Please aren't there any poeple who can help me ?I am not a perfect programmer, but i have perfect programmers' habits [ i think so :)] Try the links below, they might be of some help to you.http://msdn2.microso...

Getting Information from the Controls (TemplateField or BoundField ) from any of the Data Presentation Controls
Hello Everybody,I have a very important question for me.For example, I have a GridView.It has three BoundFields and one TemplateFieldI want to get information from any of the record (row,line etc ) using any of the BoundFields or TemplateFields.And also I want to accomplish this not only with GridView but also other Data Presentation Controls, DetailsView FormView and Repeater.Shortly, Can anybody help me how to refer Controls in GridView, FormView, DetailsView, RepeaterPS: I have searched in Google and many sites,forums. But I couldn't see any solution and see that many people ask the same ...

using controlS to control a gridview
This question is probably posted but i did not bother to look at 10,000+ posts so i am sorry. I've seen the tutorial where he builds a dataset and uses a gridview and controls the gridview with the drop down list box. What i am trying to do is to control the gridview with 2 drop down list boxes. First select the Country you life in and then the State. I've looked at the grid view properties but couldn't find where i can add another parameter. Is it possible to control a grid view (or any form of displaying the information) with more than 1 controller? Thank You.  ...

Bind Data to an Image Control not in a Data Presentation Control
I've been searching for two days but I don't really know what to search for.I'm making a site for a photographer.  The Default.aspx page displays Albums by showing a title, image and description from the database table Albums. Click an album to view the contents and it passes the QueryString which is AlbumName.  The ViewAlbum.aspx page uses the QueryString to display an UpdatePanel holding a Large Image and a Repeater full of dynamically filled ImageButtons for thumbs.  Both are from the database table Photos and are retrieved using an ObjectDataSource. Click the ...

Using Data Controls Without Using ObjectDataSource Control
Hi, I've been looking on the Internet for a tutorial that would show me how to use the data conrols (FormView, GridView etc) without using an ObjectDataSource (or any other data source control).  The reason is that I want to use a formview and gridview from within another formview control to create a single form  that would allow me to insert, update and delete an order and its order details at the same time. I thought that this could be achieved by having a DataSet containing two DataTable objects in the code-behind with the Order DataTable containing one row to repres...

Problem in Using DropDownList Control to select a selected row of SqlDataSource that is under GridView Control
Hi all,In my SQL Server Management Studio Express, I have a database "ChemDatabase" that has a table "LabData"  formatted in the following way: SampleID int PRIMARY KEY, SampleName nvarchar(25), ChemicalName, nvarchar(25), Concentration decimal(6.2) with 5 rows of records in this .dbo table. In my Visual Web Developer Express, I created a website "RPD-TCE" for extracting a row of record from the LabData table by using a DropDownList, a GridView and a SqlDataSource.  I want to click DropDownList to list one number of S...

i have work on gridview control.in that i have 3columns.name as subject,bookname,link. in this some link column data are very large.according to that data(no spaces in that data)gridview has changed.i
hi,i have work on gridview control.in that i have 3columns.name as subject,bookname,link. in this some link column data are very large.according to that data(no spaces in that data)gridview has changed.i want display half of the data and remaining display like this.(ex:http://ww.yahoo.com...........).how can i display like this,and one more thing is always the column size will constant. Try something like this: <asp:templatefield headertext="Link"> <itemtemplate> <asp:hyperlink id="HyperLink1" runat="server" navigateurl='<...

Using Calendar Control to Supply datetime data type
I have a text box control linked to a calendar extender from the Ajax Control Toolkit.  1 <asp:TextBox ID="txtStartDate" runat="server" AutoPostBack="True"></asp:TextBox> 2 <AjaxControlToolkit:CalendarExtender ID="txtStartDate_CalendarExtender" runat="server" 3 Enabled="True" TargetControlID="txtStartDate" Format="MM/DD/YYYY" 4 PopupButtonID="Image1"> 5 ...

Web resources about - Cannot get a RowFilter in a GridView control to work with a DateTime data type using a Dropdownlist as the filtering method - asp.net.presentation-controls

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 12/18/2015 5:36:01 AM