Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using datagridview rowfilter with dates
Message
 
À
13/02/2009 05:17:06
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 2.0
OS:
Windows Server 2003
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01381358
Message ID:
01383216
Vues:
28
>>I am trying to filter a datagridview with a date range. I found a site that had the syntax but I cannot get the filter to work. I don't get an error but I don't get the records I should, either. Here's my code:
>>
>>
>>        private void btnLocOfficeNotes_Click(object sender, EventArgs e)
>>        {
>>            string filterON = "";            
>>            DateTime begDate, endDate;
>>            bool testDateOK = DateTime.TryParse(this.mtxtBegDate.Text, out begDate);
>>            if (testDateOK)
>>            {
>>                if (!mmType.IsEmpty(filterON))
>>                    filterON += " AND ";
>>                filterON += "EnterDateTime >= '" + begDate.ToShortDateString() + "'";
>>               //Add hours and minutes to make sure that I get all entries for the end date, regardless of time
>>                if (this.mtxtEndDate.Text.Substring(0, 3) == "  /")
>>                {
>>                    endDate = begDate.AddHours(23).AddMinutes(59);
>>                }
>>                else
>>                {
>>                    testDateOK = DateTime.TryParse(this.mtxtEndDate.Text, out endDate);
>>                    if (testDateOK)
>>                        endDate = endDate.AddHours(23).AddMinutes(59);
>>                }
>>                filterON += " AND EnterDateTime <= '" + endDate.ToShortDateString() + "'";
>>            }
>>
>>            DataTable dtON = (DataTable)oOfficeNote.GetCurrentDataSet().Tables[0];
>>            dtON.DefaultView.RowFilter = (filterON);
>>            dtON.DefaultView.RowStateFilter = DataViewRowState.ModifiedCurrent;
>>
>>
>>I used the dates 9/30/2008 - 10/01/2008 and there were definitely records meeting the criteria but I get an empty grid when I try it. I also tried this using # rather than single quotes as delimiters for the dates, but that didn't work either. Any ideas? Thanks.
>
>
filterON = String.Format("EnterDateTime >= #{0}# and EnterDateTime <= #{1}#",  begDate.Date,endDate.Date);
Cetin
Thanks, Cetin. I don't think that was my problem, after all but I'm going to make note of this syntax. It turned out that the last statement was actually the culprit. I had to replace it with:
this.BindControl(this.grdMyGrid);
It's amazing how many different ways there are to set the same filter. Thanks again for your help.
Linda Harmes
HiBit Technologies, Inc.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform