Using system; Using system. collections; Using system. configuration; Using system. componentmodel; Using system. Data; Using system. Data. sqlclient; Using system. drawing; Using system. Web; Using system. Web. sessionstate; Using system. Web. UI; Using system. Web. UI. webcontrols; Using system. Web. UI. htmlcontrols;Namespace cj168.web { /// <Summary> /// Summary description for search. /// </Summary> Public Class search: system. Web. UI. Page { Protected system. Web. UI. webcontrols. datalist datalistsearchresult; Protected system. Web. UI. webcontrols. Label lbltxtsearch; Protected system. Web. UI. webcontrols. Label lblrecordcount; Protected system. Web. UI. webcontrols. Label lblcurrentpage; Protected system. Web. UI. webcontrols. Label lblpagecount; Protected system. Web. UI. webcontrols. Label lblpagerange; Protected system. Web. UI. webcontrols. linkbutton lbnprevpage; Protected system. Web. UI. webcontrols. linkbutton lbnnextpage; String txtsearch; Int pagesize, recordcount, pagecount, currentpage;
Public Search () { Page. init + = new system. eventhandler (page_init ); } Private void page_load (Object sender, system. eventargs E) { // Put user code to initialize the page here Txtsearch = request. Params ["txtsearch"]; If (txtsearch! = NULL) {Txtsearch = txtsearch. Replace ("'","");
Lbltxtsearch. Text = txtsearch; // Set pagesize Pagesize = 10; // Calculate the total number of records Recordcount = calculaterecord (); Lblrecordcount. Text = recordcount. tostring (); If (! Page. ispostback) {
Dosearch (); Currentpage = 0; Viewstate ["pageindex"] = 0; // Calculate the total number of pages Pagecount = recordcount/pagesize; If (recordcount % pagesize> 0) Pagecount = pagecount + 1; Lblpagecount. Text = pagecount. tostring (); Viewstate ["pagecount"] = pagecount;
} } } // Calculate the total number of records Public int calculaterecord () { Cj168.dataaccess. magsdb dosearch = new cj168.dataaccess. magsdb (); Return dosearch. getsearchresultcount (txtsearch );
} Void dosearch () { Int startindex; Int fromitem, toitem;
// Set the import start and end addresses Startindex = currentpage * pagesize; Cj168.dataaccess. magsdb dosearch = new cj168.dataaccess. magsdb (); Datalistsearchresult. datasource = dosearch. getsearchresult (txtsearch, startindex, pagesize ); Datalistsearchresult. databind (); Lbnnextpage. Enabled = true; Lbnprevpage. Enabled = true; If (currentpage = (PageCount-1) lbnnextpage. Enabled = false; If (currentpage = 0) lbnprevpage. Enabled = false; Lblcurrentpage. Text = (currentpage + 1). tostring (); Fromitem = startindex + 1; Toitem = startindex + pagesize; If (recordcount <toitem) Toitem = recordcount; Lblpagerange. Text = fromitem + "-" + toitem; } Public void page_onclick (Object sender, commandeventargs E) { Currentpage = (INT) viewstate ["pageindex"]; Pagecount = (INT) viewstate ["pagecount"]; String cmd = E. commandname; // Identify cmd to determine the page turning direction Switch (CMD) { Case "Next ": If (currentpage (PageCount-1) currentpage ++; Break; Case "Prev ": If (currentpage> 0) currentpage --; Break; } Viewstate ["pageindex"] = currentpage; Dosearch ();
}
Private void page_init (Object sender, eventargs E) { // // Codegen: This call is required by the ASP. NET web form designer. // Initializecomponent (); }
# Region web form designer generated code /// <Summary> /// Required method for designer support-do not modify /// The contents of this method with the code editor. /// </Summary> Private void initializecomponent () { This. Load + = new system. eventhandler (this. page_load ); } # Endregion } } |