1. Define a citycounty. CS file, as follows:
Using system; using system. collections. generic; using system. LINQ; using system. web; using system. runtime. serialization; // <summary> // Summary of citycounty /// </Summary> [datacontract] public class citycounty {[datamember] private int menu_id; public int menu_id {get {return menu_id;} set {menu_id = value;} [datamember] private string menu_name; Public String menu_name {get {return menu_name ;} set {menu_name = value ;}}}
2. Define a JSON processing class. The tojson. CS file is as follows:
Using system; using system. collections. generic; using system. LINQ; using system. web; using system. runtime. serialization. JSON; using system. io; /// <summary> /// Summary of jsonhelper /// </Summary> Public static class jsonhelper {// convert to JSON format and output public static string tojson (this object OBJ) {datacontractjsonserializer serializer = new datacontractjsonserializer (obj. getType (); stream = new memorystream (); serializer. writeobject (stream, OBJ); stream. position = 0; streamreader = new streamreader (Stream); Return streamreader. readtoend ();}}
3. Define the defa4.4.aspx and default4.aspx. CS files as follows:
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default4.aspx. cs" inherits = "default4" %> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml">
Using system; using system. collections. generic; using system. LINQ; using system. web; using system. web. ui; using system. web. UI. webcontrols; using USTC; using system. data; public partial class default4: system. web. UI. page {DM dm = new DM (); protected void page_load (Object sender, eventargs e) {If (! Ispostback) {string strsql = "select * From uds_menu where menu_id like '% ____ 00%'"; dataset DS = DM. getsql (strsql); this. dropdownlist1.datasource = Ds; this. dropdownlist1.datatextfield = "menu_name"; this. dropdownlist1.datavaluefield = "menu_id"; this. dropdownlist1.databind (); this. dropdownlist1.items. insert (0, "-- select city --");}}}
4. Define the default5.aspx and default5.aspx. CS files as follows:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="TEST_Default5" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using USTC;using System.Data;public partial class TEST_Default5 : System.Web.UI.Page{ DM dm = new DM(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { IList<CityCounty> list = new List<CityCounty>(); string id = Request.QueryString["id"].ToString(); string strSQL = "select Menu_ID,Menu_Name from UDS_Menu where Super_Menu_ID=" + int.Parse(id); DataSet ds = dm.getsql(strSQL); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { CityCounty c = new CityCounty(); c.Menu_ID = Convert.ToInt32(ds.Tables[0].Rows[i]["Menu_ID"].ToString()); c.Menu_Name = ds.Tables[0].Rows[i]["Menu_Name"].ToString(); list.Add(c); } Response.Write(list.ToJson()); Response.End(); } }}