局部刷新AJAX的用法。DropDownList联动

本文介绍如何在ASP.NET应用中使用AjaxPro实现无刷新下拉列表联动效果,包括添加AjaxPro.2.dll、配置web.config及前后台代码示例。

1、先添加AjaxPro.2.dll到bin里。

2、在web.conf里添加

<httpHandlers>
      <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2"/>

</httpHandlers>

3.在要用到位置的后台添加:后台:

public partial class Admin_news_picture_add : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

           AjaxPro.Utility.RegisterTypeForAjax(typeof(Admin_news_picture_add));//名字要一样

    }

}

 

//呆会前台要调用这个方法

[AjaxPro.AjaxMethod]
public static DataSet DropDownList1Result(int ddl1)
{
     DataSet dlist = Scms.SystemCms.news_system_api.GetSmallclassByBigId(ddl1);
     return dlist;
}

 

3、前台:DropDownList1控键、DropDownList3控键。这两个控键实现无刷新连动

    <script type="text/javascript">
         function ddl1Result()
        { 
            var ddl1=document.getElementById("<%=DropDownList1.ClientID%>");
            if (ddl1.value != "")
            {

                //ddl1.value为前台到到控键值传给要调用的后台方法。get_Result_CallBack后台方法调用完后把返回值

               // 传给这个方法。如 果调用后台方法后没有返回值的话。不用写“get_Result_CallBack”
                Admin_news_picture_add.DropDownList1Result(ddl1.value,get_Result_CallBack);


            }
        }
        function get_Result_CallBack(response)
        {         
            document.all("<%=DropDownList3.ClientID%>").length=0;
            if (response.value != null)
            {                   
                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].smallchinesename;
                        var id=ds.Tables[0].Rows[i].bh;

                        //得到的值累加到DropDownList3控键中
                        document.all("<%=DropDownList3.ClientID%>").options.add(new Option(name,id));
                    }
                 }
            }          
            return
        }
    </script>

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值