日期:2014-4-24 浏览次数:20269次

在用户注册的时候需求依据不同的用户类型,重数据库中筛选出不同的产品提供应用户。想想,效果最好的只能是无刷新的方法了。

前台脚步:(js)

function fillProduction()
{
   var dwl = document.all("DropdownlistLevel");
   var htp = new ActiveXObject("microsoft.xmlhttp");
   var url = "reg.aspx?fp=" + dwl.value; htp.open("POST",url,false);
   htp.setRequestHeader("Content-Type","application/x-www-form-urlencoded") htp.send();
   var str = htp.responseText;
   if (str != "")
   {
      var mydata = str.split("$");
      if(mydata[0] != 0)
       {
          for( var i=1;i<=mydata[0];i++ )
           {
             var tmp = mydata[i].split("@");
             var item = new Option();
             item.text = tmp[0] + "|" + tmp[1] + " BV"; item.value = tmp[2];                        document.submit.DropDwonListProduction.options[i-1] = item;
           }
          document.submit.hidpid.value = document.submit.DropDwonListProduction.value;
       }
      else
      {
         var len = document.submit.DropDwonListProduction.options.length;
         for(var i=len-1;i>=0;i--)
         {
           document.submit.DropDwonListProduction.options.remove(i);
         }
         document.submit.hidpid.value = "";
       }
   }
   htp = null;
}

后台编码:

private void fillProduction()
  {
   string sql;
   sql = "select pgr_prod_descr,pgr_bv_value,pgr_prod_grp_cd from prod_grp t where t.pgr_bv_value = (select dal_bv from def_acct_level where dal_id = " + Request["fp"] + ")";   
   DataTable dt;
   dt = SQLHelper.FillDataTable(SQLHelper.CONN_STRING,CommandType.Text,sql);
   string tmp;
   if (dt.Rows.Count >0 )
   {
    tmp = dt.Rows.Count.ToString() + "$";
    for(int i=0;i<=dt.Rows.Count-1;i++)
    {
     tmp = tmp + dt.Rows[i][0].ToString() + "@" + dt.Rows[i][1].ToString() + "@" + dt.Rows[i][2].ToString() + "$";
    }    
   }
   else
   {
    tmp = "0$";
   }
   Response.Write(tmp);
  }