.net 运用ajaxpro 功能省市县联动

注意下需要下载个ajaxpro.dll文件

还有web。config   
节后面要加入

   
     
   

这个节

 

 

//前台

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="ajax_shengshiliandong_Default" %>



    无标题页
   
   
   
   


   


   

        请选择省:  请选择市:
       
           请选择县:
       
       
        
       
   

   


 

 

 

 

 

 

//后台

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class ajax_shengshiliandong_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AjaxPro.Utility.RegisterTypeForAjax(typeof(ajax_shengshiliandong_Default));
    }

    ///


    /// 页面加载的时候。调用了此方法,获取省的结果集
    ///

    ///
    [AjaxPro.AjaxMethod]
    public DataSet  band_1()
    {
        string scn = "server=.//SQLEXPRESS; database=ajaxceshi; uid=sa;pwd=123";
        string sql = "select * from province";
        SqlConnection sc = new SqlConnection(scn);
        sc.Open();
        
        SqlDataAdapter sa = new SqlDataAdapter(sql,sc);
        DataSet ds = new DataSet();
        sa.Fill(ds);
        sc.Close();

        return ds;
       
    }


    ///


    /// 选择省的时候调用了此方法,获取市的结果集
    ///

    ///
    ///
    [AjaxPro.AjaxMethod]
    public DataSet band_2(int id)
    {
        string scn = "server=.//SQLEXPRESS; database=ajaxceshi; uid=sa;pwd=123";
        string sql = "select cityname,cityid from city where id=" + id + "";
        SqlConnection sc = new SqlConnection(scn);
        sc.Open();

        SqlDataAdapter sa = new SqlDataAdapter(sql, sc);
        DataSet ds = new DataSet();
        sa.Fill(ds);
        sc.Close();

        return ds;

    }

    ///


    /// 根据id查询县的数据集,选择市的时候调用此方法,获取县结果集
    ///

    /// 前台传进来的市id
    ///
    [AjaxPro.AjaxMethod]
    public DataSet band_3(int id)
    {
        string scn = "server=.//SQLEXPRESS; database=ajaxceshi; uid=sa;pwd=123";
        string sql = "select * from xian where id=" + id + "";
        SqlConnection sc = new SqlConnection(scn);
        sc.Open();

        SqlDataAdapter sa = new SqlDataAdapter(sql, sc);
        DataSet ds = new DataSet();
        sa.Fill(ds);
        sc.Close();

        return ds;

    }


}

你可能感兴趣的:(.net 运用ajaxpro 功能省市县联动)