Listview query binding

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.