Generic handlers are similar to public modules, and all pages can be called.
General processing procedures
<%@ WebHandler language="C #"class="Setgrid"%>usingSystem;usingsystem.web; public classSetgrid:ihttphandler { public voidProcessRequest (httpcontext Context) {stringsql =""; System.Data.DataTable dttmp=NULL; stringSF =""; stringresult =""; Try { Switch(context. request["Oper"]) { case "Supplier"://suppliersql ="Select id,abbreviation,name,linkman1,tel,trmo,currency,cess from provider"; if(!string. IsNullOrEmpty (context. request["Q"]) {SF= Context. request["Q"]. ToString (). Trim (); SQL+="where abbreviation like '%"+ SF +"% ' or linkman1 like '%"+ SF +"% ' or name like '%"+ SF +"% ' or Tel like '%"+ SF +"% '"; } dttmp=pubcommon.getdatatable (sql); Result=Pubcommon.datatabletojson (dttmp); //result = "[{\" si_name\ ": \" mitsubishi \ ", \" si_linkman\ ": \" Murakami \ ", \" si_mobile\ ": \" 12-002136\ "},{\" si_name\ ": \" Simon West \ ", \" si_ linkman\ ": \" jon\ ", \" si_mobile\ ": \" 0223-26565\ "}]"; break; case "Podetail": SQL="Select 1 as gi_id,*,12 as pi_number,12 as qty from materiel Where code = ' 110010030092 '"; Dttmp=pubcommon.getdatatable (sql); if(dttmp! =NULL) {result=Pubcommon.datatabletojson (dttmp); } break; case "Query": SQL="SELECT * FROM Materiel"; Dttmp=pubcommon.getdatatable (sql); if(dttmp! =NULL) {result=Pubcommon.datatabletojson (dttmp); } break; } } Catch(Exception Ex) {} Context. Response.Write (result); Context. Response.End (); } public BOOLisreusable {Get { return false; } }}View Code
Script
//supplier$ (' #gys_key '). Combogrid ({panelwidth:350, Delay:500, Mode:' Remote ', Idfield:' ID ', TextField:' Abbreviation ', Url:'/project2/dispose/setgrid.ashx?oper=supplier ', Columns: [[{field:' Abbreviation ', title: ' abbreviation ', width:80}, {field:' Name ', title: ' supplier name ', width:120}, {field:' Linkman1 ', title: ' Contacts ', width:80}, {field:' Tel ', title: ' phone ', width:100}]], onSelect:function(rowIndex, rowdata) {$ ("#txtTax"). Val (rowdata.cess); $("#txtpay"). Val (rowdata.trmo); $("#txtcurrency"). Val (rowdata.currency); } });
Asp. NET Generic handler