This article is suitable for small data volumes. For large data volumes, another method is required. For more information, see the next article.
First of all, searching on the internet is essential. After learning about the direction of the Multi-condition combination query of linq, you can start to do it. First, write a delegate method:
Copy codeThe Code is 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;
}
Here, I put all the methods on the current page for testing.
Note that the content in this method can be changed according to the actual situation. Here I am making a message board list;
Call method. Here, the list is bound to the repeater control.
So we can do this:
Copy codeThe Code is 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: FeedBack is the object name of the data source table of my linq to SQL.
In addition, some answers to the website search are incorrect. For example, my Expression <Func <FeedBack, bool> is written as Expressionbool>, NND, despising these junk websites, and writers.
I hope you will benefit from my article!