js:
LoadClass.ashx:
<%@ WebHandler Language="C#" Class="LoadClass" %>
using System;
using System.Web;
using System.Text;
using System.Data;
public class LoadClass : IHttpHandler {
public void ProcessRequest (HttpContext context) {
// 数组 [{"ID":"275","Cname":"A1"},{"ID":"319","Cname":"A2"},{"ID":"322","Cname":"A3"}]
int strId = Convert.ToInt32(context.Request["ddlId"]);
string strSQL = "select * from Class where parent_Ptr=" strId " order by classOrder asc ";
db d = new db();
DataTable dt = d.getDT(strSQL);
StringBuilder strClass = new StringBuilder();
if (dt != null)
{
strClass.Append("[");
for (int i = 0; i < dt.Rows.Count; i )
{
strClass.Append("{");
strClass.Append(""ID":"" dt.Rows[i]["id"].ToString() "",");
strClass.Append(""Cname":"" dt.Rows[i]["classCname"].ToString() """);
if (i != dt.Rows.Count - 1)
{
strClass.Append("},");
}
}
}
strClass.Append("}");
strClass.Append("]");
context.Response.ContentType = "application/json";
context.Response.ContentEncoding = Encoding.UTF8;
context.Response.Write(strClass.ToString());
context.Response.End();
}
public bool IsReusable {
get {
return false;
}
}
}
注意:
//The background can only get the value value, not the text directly, it needs to be transferred through js and control
//Result: 275 276 277
Label1.Text = Request.Form[ddl1.UniqueID ] " " Request.Form["ddl2"] " " Request.Form[ddl3.ClientID.Replace("_", "$")] ;Problems encountered: The value of the drop-down box text is transferred through the HiddenField control
Assign the value of the selected drop-down box to the hidden control:
After selecting the drop-down box, the value dynamically assigned to the HiddenField control cannot correspond to the value selected in the drop-down box!
It may be related to initialization. Where should the assignment code be placed? Or is there any good method? Welcome to discuss?