ASHX Processing page
stringJsonlist ="["; IList<Models.Channel> IList =BLL. Channelmanager.getallchannels (); List<Models.Channel> list =Publiccs.ilisttolist (IList); // IList conversion to list Jsonlist+="{id:0,channelname: ' Top column '},"; foreach(Models.channel Channelinchlist) {Jsonlist+="{ID:"+ channel. Id.tostring () +", ChannelName: '"+ channel. ChannelName +"'},"; } jsonlist= Jsonlist.substring (0, Jsonlist.length-1); Jsonlist+="]"; Context. Response.Write ("[{\ "message\": \ "success \", \ "actiontype\": \ ""+ Action +"\ ", \" jsonlist\ ": \""+ Jsonlist +"\ ", \" status\ ": \" Success\ "}]"); Context. Response.End (); return;
/// <summary> ///IList converted to list/// </summary> /// <typeparam name= "T" ></typeparam> /// <param name= "list" ></param> /// <returns></returns> Public StaticList<t> ilisttolist<t> (ilist<t>list) {t[] array=Newt[list. Count]; List. CopyTo (Array,0); return NewList<t>(array); }
HTML page
< Li >< label > Parent column </label><id= "ParentID" > </Select> </li>
Js
var jsonlist={}; =eval (Data[0]. Jsonlist); // Convert a JSON array to a JSON object for (var i=0;i<jsonlist.length;i++) // bind a JSON object to a select { $ ("#ParentID"). Append ("<option value= '" +jsonlist[i].id+ ">" +jsonlist[i]. Channelname+ "</option>"); }
Select binding JSON Array object ASP.