多级无刷新联动(GB2312编码转换为UTF-8未取得满意效果)

//此方法根据济览器类型取得对应的传值方法
function getType()
            {
                var A 
= null;
                
try
                {
                    A 
= new ActiveXObject("Msxml2.XMLHTTP");
                }
                
catch(e)
                {
                    
try
                    {
                        A 
= new ActiveXObject("Microsoft.XMLHTTP");
                    }
                    
catch(oc)
                    {
                        A 
= null;
                    }
                }
                
if(!&& typeof XMLHttpRequest != "undefined")
                {
                    A 
= new XMLHttpRequest();
                }
                
return A;
            }
            function Go(obj)
            {
                
//得到第一个下拉列表的值,用于取第三个DropDownList的值时作条件
                var firstValue = document.getElementById("DropName").value;
                
//得到第二个下拉列表的值,用于绑定TextId时作为参考
                var secondValue = "no";
                
if(document.getElementById("DropType").options.length == 0)
                {
                    secondValue 
= "no";
                }
                
else
                {
                    secondValue 
= document.getElementById("DropType").value;
                }
                
//得到当前的下拉列表的值
                var currentControlValue = obj.value;
                
//取得当前下拉列表的名称,用来进行不同的绑定
                var currentControlName = obj.name;
                
//传递控件名称和值给处理页面
                var weburl="HalfFinishedProduct_DropProcess.aspx?CCV='"+currentControlValue+"'&CCN='"+currentControlName+"'&FV='"+firstValue+"'&SV='"+secondValue+"'";
                
//初始化xmlhttp对象
                var xmlhttp = getType();
                
//提交数据
                xmlhttp.open("get",weburl,true);
                
//如果成功返回数据
                xmlhttp.onreadystatechange = function()    
                {
                    
if(xmlhttp.readyState == 4)
                    {
                        
//得到服务器返回的数据
                        var result = xmlhttp.responseText;
                        
if(currentControlName == "DropName")
                        {
                            
                            
//清空要绑定的DropDownList所有下拉项
                            document.getElementById("DropType").length = 0;
                            document.getElementById(
"DropColor").length = 0;
                        
                            document.getElementById(
"DropType").options.add(new Option("所有型号","0"));
                            document.getElementById(
"DropColor").options.add(new Option("所有颜色","0"));
                        
                            
//判断返回的数据是否为空
                            if(result != "")
                            {
                                
//把接收到的数据按 ,  分割成数组
                                var allArray = result.split(",");
                                
//循环这个数组
                                for(var i = 1; i<allArray.length; i++)
                                {
                                    var thisArray 
= allArray[i].split("|");
                                    
//为另外两个下拉列表添加条目
                                    document.getElementById("DropType").options.add(new Option(thisArray[0].toString(),thisArray[0].toString()));
                                    document.getElementById(
"DropColor").options.add(new Option(thisArray[1].toString(),thisArray[1].toString()));
                                }
                            }
                        }
                        
else if(currentControlName == "DropType")
                        {
                            document.getElementById(
"DropColor").length = 0;
                            document.getElementById(
"DropColor").options.add(new Option("所有颜色","0"));
                            
//判断返回的数据是否为空
                            if(result != "")
                            {
                                
//把接收到的数据按 ,  分割成数组
                                var allArray = result.split(",");
                                
for(var i = 1; i<allArray.length; i++)
                                {
                                    var thisArray 
= allArray[i].split("|");
                                    
//绑定颜色控件的值
                                    document.getElementById("DropColor").options.add(new Option(thisArray[1].toString(),thisArray[1].toString()));
                                }                
                                
                            }
                            
                        }
                        
else if(currentControlName == "DropColor")
                        {
                            
if(result != "")
                            {
                                    
//绑定颜色控件的值
                                    document.getElementById("TextID").value = result;
                            }
                            
                        }
                    }
                }
                xmlhttp.send(
null);
            }


//根据页面传过来的信息取得对应的数据然后作用字符串传递给请求页面
//取得控件的名称
        public string droName
        {
            
getreturn (string)ViewState["DropName"];}
            
set{ViewState["DropName"= value;}
        }
        
//取得DropName的值
        public string strDName
        {
            
get{return (string)ViewState["StrName"];}
            
set{ViewState["StrName"= value;}
        }
        
//取得DropType的值
        public string strTName
        {
            
get{return (string)ViewState["StrTName"];}
            
set{ViewState["StrTName"= value;}
        }

        
private void Page_Load(object sender, System.EventArgs e)
        {
            
// 在此处放置用户代码以初始化页面

            droName 
= "";
            
if(Request.QueryString["FV"!=null)
            {
                strDName 
= Request.QueryString["FV"].Replace("'","");
            }
            
if(Request.QueryString["SV"!=null)
            {
                strTName 
= Request.QueryString["SV"].Replace("'","");
            }
            BindDrop();
        }
        
private void BindDrop()
        {
            
string strName = "";

            
//获取传过来的当前下拉列表的选择值
            if(Request.QueryString["CCV"!= null)
            {
                strName 
= Request.QueryString["CCV"].Replace("'","");
            }
            
if(Request.QueryString["CCN"!= null)
            {
                
//获取传过来的DropDownList的名称来作相应的绑定
                droName = Request.QueryString["CCN"].Replace("'","");
            }
            
//判断是否传值 过来
            if(strName+"aa" != "aa" && droName == "DropName")
            {
                
//触发DropName事件
                BindTypeColor(strName);
            }
            
else if(strName+"aa" != "aa" && droName == "DropType")
            {
                
//触发DropType事件
                BindColor(strDName,strName);
            }
            
else if(strName+"aa" != "aa" && droName == "DropColor")
            {
                
//触发DropColor事件
                BindTextId(strDName,strTName,strName);
            }
        }
        
/// <summary>
        
/// 第一次选择,绑定颜色和类型
        
/// </summary>
        
/// <param name="strName"></param>
        public void BindTypeColor(string strName)
        {
            
string result = "";
            Response.Clear();
            
string selectTc = "select type, Color from HalfFinishedProductDetails where ProductName = @name";
            SqlCommand comm 
= new SqlCommand(selectTc,conn);
            conn.Open();
            comm.Parameters.Add(
new SqlParameter("@name",SqlDbType.VarChar,20));
            comm.Parameters[
"@name"].Value = strName;
            SqlDataReader sdr 
= comm.ExecuteReader();
            
while(sdr.Read())
            {
                result 
+= ","+sdr.GetString(0)+"|"+sdr.GetString(1);
            }
            sdr.Close();
            conn.Close();
            Response.Write(result);
            Response.Flush();
            Response.Close();
        }
        
/// <summary>
        
/// 第二次选择,根据绑定颜色
        
/// </summary>
        
/// <param name="strDName"></param>
        
/// <param name="strType"></param>
        public void BindColor(string strDName, string strType)
        {
            
string result = "";
            Response.Clear();
            
string selectTc = "select HalfFinishedProductID,Color from HalfFinishedProductDetails where ProductName = @name and Type = @type";
            SqlCommand comm 
= new SqlCommand(selectTc,conn);

            comm.Parameters.Add(
new SqlParameter("@name",SqlDbType.VarChar,20));
            comm.Parameters[
"@name"].Value = strDName;

            comm.Parameters.Add(
new SqlParameter("@type",SqlDbType.VarChar,20));
            comm.Parameters[
"@type"].Value = strType;

            conn.Open();
            SqlDataReader sdr 
= comm.ExecuteReader();
            
while(sdr.Read())
            {
                
try
                {
                    result 
+= ","+sdr.GetInt32(0).ToString()+"|"+sdr.GetString(1);
                }
                
catch(Exception eee )
                {
                    Response.Write(eee.Message);
                }
                
            }
            sdr.Close();
            conn.Close();
            Response.Write(result);
            Response.Flush();
            Response.Close();
        }
        
/// <summary>
        
/// 第三次选择,跟根前面的名称,类型,颜色三个条件确定TextTd的值
        
/// </summary>
        public void BindTextId(string name, string type, string color)
        {
            
string result = "";
            Response.Clear();
            
string selectId = "select HalfFinishedProductID from HalfFinishedProductDetails where ProductName = @name and Type = @type and color=@color";
            SqlCommand comm 
= new SqlCommand(selectId, conn);
            
            comm.Parameters.Add(
new SqlParameter("@name",SqlDbType.VarChar,20));
            comm.Parameters[
"@name"].Value = name;

            comm.Parameters.Add(
new SqlParameter("@type",SqlDbType.VarChar,20));
            comm.Parameters[
"@type"].Value = type;

            comm.Parameters.Add(
new SqlParameter("@color",SqlDbType.VarChar,20));
            comm.Parameters[
"@color"].Value = color;

            conn.Open();
            SqlDataReader sdr 
= comm.ExecuteReader();
            
while(sdr.Read())
            {
                result 
= sdr.GetInt32(0).ToString();
            }

            sdr.Close();
            conn.Close();
            Response.Write(result);
            Response.Flush();
            Response.Close();
        }


如果WebConfig里
<globalization requestEncoding="UTF-8" responseEncoding="UTF-8"/>
设置为UTF
-8则xmlHttp不能传输中文,应改为GB2312


//vbscript将gb2312转为uft-8的代码,用javascript调用时不成功。
<script language="vbscript" >
            Function DeCodeAnsi(s)
            Dim i, sTmp, sResult, sTmp1
            sResult 
= ""
            For i
=1 To Len(s)
            If Mid(s,i,
1)="%" Then
            sTmp 
= "&H" & Mid(s,i+1,2)
            If isNumeric(sTmp) Then
            If CInt(sTmp)
=0 Then
            i 
= i + 2
            ElseIf CInt(sTmp)
>0 And CInt(sTmp)<128 Then
            sResult 
= sResult & Chr(sTmp)
            i 
= i + 2
            Else
            If Mid(s,i
+3,1)="%" Then
            sTmp1 
= "&H" & Mid(s,i+4,2)
            If isNumeric(sTmp1) Then
            sResult 
= sResult & Chr(CInt(sTmp)*16*16 + CInt(sTmp1))
            i 
= i + 5
            End If
            Else
            sResult 
= sResult & Chr(sTmp)
            i 
= i + 2
            End If
            End If
            Else
            sResult 
= sResult & Mid(s,i,1)
            End If
            Else
            sResult 
= sResult & Mid(s,i,1)
            End If
            Next
            DeCodeAnsi 
= sResult
            End Function
        
</script>
如果将它放在
<script language="javascript">
</script>
之前,javascript里的 value属性会报错,放在这个之后又达不到转换的效果。

暂时还不知如何在
<globalization requestEncoding="UTF-8" responseEncoding="UTF-8"/>这种设置的情况下用javascript转换编码格式。   
posted on 2005-11-29 09:51  泽来  阅读(1418)  评论(0编辑  收藏  举报