This article is suitable for the small amount of data, for large data, need to use another way, see the next
First of all, from the Internet search, is essential, probably understand the LINQ multiple conditional combination query direction, began to start, first, write a delegate method:
Copy Code code as follows:
private bool Getcondition (FeedBack FB)
{
bool Boolresult = true;
int f_type = Int32.Parse (Ddlftype.selectedvalue);
int isclose = Int32.Parse (Ddlisclose.selectedvalue);
int isTrue = Int32.Parse (Ddlistrue.selectedvalue);
string keyword = tbxKeyword.Text.FilterInjectStr ();
if (f_type!= 0)
{
Boolresult &= FB. F_type = = F_type;
}
if (Isclose!=-1)
{
Boolresult &= FB. Isclose = = Isclose;
}
if (isTrue!=-1)
{
Boolresult &= FB. IsTrue = = IsTrue;
}
if (!keyword. IsNullOrEmpty ())
{
Boolresult &= FB. Contentinfo.indexof (keyword) >-1;
}
return boolresult;
}
Because it was a test, I put all the methods on the current page.
Note that the content of this method can be changed according to the actual situation, what I do here is a list of the message board;
Calling the way that I'm here the list is bound to the Repeater control.
So you can do this:
Copy Code code as follows:
private void Listdatabind ()
{
expression<func<feedback,bool>> expr = n => getcondition (n);
list<feedback> pagedata = FeedBacks.AllFeedBacks.Where (Expr.compile ()). ToList ();
Feedbacklist.datasource = Pagedata;
Feedbacklist.databind ();
}
Note that feedback is the object name of the data source table for my LINQ to SQL.
In addition, the site search some of the answers are wrong, such as Will my expression<func<feedback,bool>> written expressionbool>>,nnd, despise these spam sites. and a writer.
I hope you beginners can benefit from my article!