supegong  

以下为从不同部门ddlSsbm中选择不同的责任人ddlZrr

1.新建类

 public Cfunction()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }

  public static DataSet getSsbm(string strYgid)//得到所属部门,其它页面可直接用,见后面的调用
  {
   pub mpub = new pub();
   return mpub.getBm1(strYgid);
  }
  public static DataSet getZrr(string strZrr)//得到责任人.
  {
   pub mpub = new pub();
   return mpub.getBmyg1("0",strZrr);
  }


  [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
  public DataSet getBmZrr(string strBmdm,string strYgid)//根据所属部门值返回责任人
  {
   pub mpub = new pub();
   return mpub.getBmyg1(strBmdm,strYgid);
  }
 }

 

2.在使用的页面后台中加入

private void Page_Load(object sender, System.EventArgs e)

{

   Ajax.Utility.RegisterTypeForAjax(typeof(Cfunction));
   if(!this.IsPostBack)
   {
    this.ddlSsbm.DataSource = Cfunction.getSsbm(strYgid);
    this.ddlSsbm.DataTextField = "BMMC";
    this.ddlSsbm.DataValueField = "BMDM";
    this.ddlSsbm.DataBind();

    this.ddlZrr.DataSource = Cfunction.getZrr(strYgid);
    this.ddlZrr.DataTextField = "YGXM";
    this.ddlZrr.DataValueField = "YGID";
    this.ddlZrr.DataBind();

    this.ddlSsbm.Attributes.Add("onclick","ssbmResult();");
   }

}

3.页面的前台加入

<1>对应后台的红字,并在事件后新增事件参数get_bmZrr

function ssbmResult()

 { var bm=document.getElementById("ddlSsbm");

   var ygid=document.getElementById("ygid");

   Cfunction.getBmZrr(bm.value,ygid.value,get_bmZrr); }

<2>从取得的值加入ddlZrr

function get_bmZrr(response)

{ if (response.value != null) { document.all("ddlZrr").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].YGXM;

var id=ds.tables[0].rows[i].YGID;

document.all("ddlZrr").option.add(new option(name,id));

 

posted on 2009-12-09 11:19  supegong  阅读(136)  评论(0)    收藏  举报