According to the book, we have achieved basic display and sorting, so today we will perform queries and paging.
First, pass common parameters to implement conditional query.
To query by conditions, we need to modify our original query method.
[DataObjectMethod(DataObjectMethodType.Select)] public static List<UserInfo> GetUserInfoList(string name, string sort) { ........ }
Here we add a parameter to input the name of the user to be queried.
However, you must note that you must do one thing after modifying the subsequent method.
Configure the data source.
Because we modified the following method parameters, this is also changed. If you do not reconfigure the data source, an error is reported.
When you reconfigure the data source, you can set the source of the value for your parameter.
Here, I set the value source to the control type for the name parameter. the control name is txt_name, so that you can change the content of the returned set by passing the value. in addition, because the data source we specified is txt_name, When you click the query button, it will automatically re-bind the gridview control. that is, you no longer need to execute the databind method of the gridview.
The above has already achieved a little effect, so we can achieve the final result we want this time.
When passing values, you will find that there are still many parameters when multiple query conditions are passed. in addition, we already have the userinfo class, so we can simply put the content of the condition to be queried into an object and pass it through its attribute set method to verify it.
public static List<UserInfo> GetUserInfoList(UserInfo info,int start,int max, string sort){......}
So we will do the paging for the refer.
According to our requirements, the original method is rewritten to the "break" method. Two parameters of an object and paging are passed.
Here we can set these two parameters in objectdatasource as we mentioned in the sorting method. They are
Startrowparametername and maximumrowsparamtername
However, here I use the third-party paging control by assigning a value to the selecting event of objectdatasource.
Protected void objectdatasource1_selecting (Object sender, objectdatasourceselectingeventargs e) {models. userinfo info = new models. userinfo (); info. uname = txt_name.text; E. inputparameters ["info"] = Info; E. inputparameters ["start"] = input value; E. inputparameters ["Max"] = input value ;}
In this way, we can pass the Info Object assigned by ourselves and the start and max values obtained from the paging control into the select method in BLL.
This article describes how to dynamically pass your values to the predefined methods through events.
Note: because the current parameter is assigned only later, you must add a sentence to your query button.
Protected void btn_query_click (Object sender, eventargs e) {gridview1.databind (); // You must rebind the gridview here}