Ajax联动下拉框的实现例子
Ajax联动下拉框的实现例子
字串8
AjaxPro.dll 下载地址 http://ajaxpro.schwarz-interactive.de/download/ajaxpro.zip
字串6
Web.Config
<?xml version="1.0"?>
<configuration>
<system.web>
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
</httpHandlers>
</system.web>
</configuration> 字串7
AjaxTest.aspx 字串3
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxTest.aspx.cs" Inherits="AjaxTest" %>
字串3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
字串4
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title> 字串5
</head> 字串1
<body>
<script language="javascript" type="text/javascript">
function areaResult()
{
var area=document.getElementById("DropDownList1");
//alert(area.value);
AjaxTest.GetCityList(area.value,get_city_Result_CallBack);
}
function get_city_Result_CallBack(response)
{
if (response.value != null)
{
document.all("DropDownList2").length=0;
var ds = response.value;
if(ds != null && typeof(ds) == "object" && ds.Tables != null)
{
for(var i=0; i<ds.Tables[0].Rows.length; i++)
{
var name=ds.Tables[0].Rows[i].name;
var id=ds.Tables[0].Rows[i].id;
document.all("DropDownList2").options.add(new Option(name,id));
}
//document.all("TextBox1").value="";
}
}
return
} 字串1
</script>
<form id="form1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
<br />
</form>
</body>
</html>
字串7
AjaxTest.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MeetWeb;
public partial class AjaxTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(AjaxTest));
if (!Page.IsPostBack)
{
BindData();
字串7
}
}
private void BindData()
{
DataSet ds = new DataSet();
String sql = "Select id,name from test";
try
{
ds = GetDataSet(sql, "test");
this.DropDownList1.DataSource = ds.Tables[0];
this.DropDownList1.DataTextField = "name";
this.DropDownList1.DataValueField = "id";
this.DropDownList1.DataBind();
字串4
this.DropDownList1.Attributes.Add("onclick", "areaResult();");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
} 字串6
public static DataSet GetDataSet(string sql,string aa)
{
MeetWeb.SqlDataBase a = new MeetWeb.SqlDataBase("server=localhost\\PMSERVER;uid=sa;pwd=sa;database=test");
DataSet ds = new DataSet();
ds=a.CreateSet(sql, aa);
return ds;
} 字串9
[AjaxPro.AjaxMethod]
public DataSet GetCityList(int id)
{
string sql = "select name from test where id='" + id + "'";
return GetDataSet(sql,"test");
}
字串4
} 字串1
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
· .NET 适配 HarmonyOS 进展
· 如何给本地部署的DeepSeek投喂数据,让他更懂你
· 超详细,DeepSeek 接入PyCharm实现AI编程!(支持本地部署DeepSeek及官方Dee
· 用 DeepSeek 给对象做个网站,她一定感动坏了
· .NET 8.0 + Linux 香橙派,实现高效的 IoT 数据采集与控制解决方案
· .NET中 泛型 + 依赖注入 的实现与应用