设置首页  |   加入收藏  |  联系我们   
您的位置: 主页>网站设计>AJAX>正文
Ajax简单示例之改变下拉框动态生成表格
文章来源:  编辑:  发布时间:2007-12-14

1.建立一个aspx页面,html代码
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
        var xmlHttp;

        function createXMLHttpRequest()
        {
            if (window.ActiveXObject)
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            else if (window.XMLHttpRequest)
            {
                xmlHttp = new XMLHttpRequest();
            }
        }
           
        function startRequest()
        {
            //debugger;
            var ProvinceID=document.getElementById("DropDownList1");          
            createXMLHttpRequest();
            xmlHttp.onreadystatechange = handleStateChange;
            xmlHttp.open("GET", "?ProvinceID="+ProvinceID.value, true);
            xmlHttp.send(null);
        }
           
        function handleStateChange()
        {
            if(xmlHttp.readyState == 4) //0(未初始化);1(正在装载);2 (装载完毕);3 (交互中);4 (完成)
            {
                if(xmlHttp.status == 200) //200(OK);404(not found)
                {
                    document.getElementById("gridiv").innerHTML=xmlHttp.responseText;
                }
            }
        }
        </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>  
    </div>
    <div id ="gridiv"></div>
    </form>
</body>
</html>2.cs代码
using System.Data.SqlClient;
protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.DropDownList1.Attributes.Add("onchange", "return startRequest();");
            ListProvince();
            if (ProvinceID != "")
            {
                GetCityByProvinceID(ProvinceID);
            }
        }
    }

    property#region property
    private string ProvinceID
    {
        get
        {
            if (Request["ProvinceID"] != null && Request["ProvinceID"].ToString() != "")

 
Tags:动态 生成 表格 改变 简单 if ProvinceID server runat

Google
 
上一篇: AJAX支持的自动填充表单   下一篇: AJAX如何与后台交互
【返回顶部】 【打印】 【大】 【中】 【小】 【关闭】

 我来说两句
用户名: 新注册) 密码: 匿名评论 [论坛讨论]
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 相关文章
 热门文章

 
版权所有  2005-2006  Linux集中营  闽ICP备07500055号