This problem is to implement: Display and query data in the same listview. That is, when the page is loaded for the first time, the listview loads all the data, and then the user can perform the query action on the page. The results are still displayed in the listview, and the binding operation such as deletion still exists.
Step 1: bind the listview to datasource according to the normal binding operation. Then, set datasource to the method used to query all data in the Dal layer. Here, my method is listall ().
Step 2: In the Click Event of the query button, we use the followingCodeChange the query method:
Protected void Button#click ( Object Sender, Eventargs E ){ // Obtain the query conditions entered by the user String Key = textbox1.text; // Clear the parameter set of the query method (the collection cannot contain useless parameters) Objectperformance1.selectparameters. Clear (); // Check whether the user has entered the query Conditions If (Key. Trim (). length> 0 ){ // If a query condition is entered, the query method with parameters is used. Objectperformance1.selectmethod = "Listbyname" ; // Create a query parameter. The constructor must input the following parameters in sequence: Parameter Name, data type, and parameter value. Parameter Param = New Parameter ( "Posname" , System. Data. Dbtype . String, key ); // Add parameters to the query parameter set of the Data Source Objectperformance1.selectparameters. Add (PARAM );} Else { // If no query conditions are entered, all query methods are still used. Objectperformance1.selectmethod = "Listall" ;}}
Step 3: Now you can run the check results. After the selectmethod is changed, the listview will automatically refresh the display content. No problem with binding other operations.
The problem is solved by modifying the selectmethod of datasource to change the query.