Filter Expression based on Multiple Conditions

Apr 14 2009 5:52 PM

I have a simple DataList bound to a SQLDatasource to show announcements.  Based on the user's permissions, the DataList is filtered to show only certain items.

In addition I have two DatePickers "fromDate" and "toDate" that I would like to filter the announcements so people can just show dates from certain days up to another day that they select.

Currently I have a button that refines the search. Here is the code below.  I'm new and know how to do this from a query, but when applying a filter expression I get an error code 12 missing operator.

protected void DateFilter_Click(object sender, EventArgs e)

{

annSrc.FilterExpression = "A_date >= {0} AND A_date <= {1}";

annSrc.FilterParameters.Add("A_date", GMfromDatePicker.Date.ToString());

annSrc.FilterParameters.Add("A_date", GMtoDatePicker.Date.ToString());

}

I've also tried

protected void DateFilter_Click(object sender, EventArgs e)

{

annSrc.FilterExpression = "A_date >= " + GMfromDatePicker.Date.ToString() + " AND A_date <= " + GMtoDatePicker.Date.ToString();

}

 

Any ideas?


Answers (2)