需求是这样的,我现在有两个listbox,1和2 ,我想点一下1中的任何一个item,然后去数据库中去搜col列符合选中的那个值的所有 符合条件记录的某一列(col_ok)列,显示在2中。如果我要点1中的其他值,2中相应的跟着变化。

解决方案 »

  1.   

    想法有了自己应该可以做了啊!先listbox1选好后,listbox1做为参数在数据库中用sql查出啊!
      

  2.   

    用javascript就得用ajax.
    很简单的.
      

  3.   

    我以前是弄winform的,对js不太明白。
    function  SelectOnea()
            {
                var lst1=window.document.getElementById("Listbox1");
                var lstindex=lst1.selectedIndex;
                if(lstindex<0)
                    return;
                var v = lst1.options[lstindex].value;
                var t = lst1.options[lstindex].text;
               
               
            } 
    我要是能把v,t的值取出来,估计我就有办法了
      

  4.   

    2003用__doPostBack
    2005用document.all.btn.click();--不知道为什么__doPostBack在2005上不能用了。
      

  5.   

    这位仁兄,我刚才去网上找__doPostBack的相关资料了。可是看的还是一头雾水,能否把关键的几步帮我说下。还有,我上面的代码跟__doPostBack怎么联系起来。。
      

  6.   

    用js调用 webservice 来实现应该更好些——
    ……
    var isIE = true;
    if(window.XMLHttpRequest)
    {
    isIE = false;
    }
    var xmlHttp;
    function GetXMLHttpRequest()
    {
    return isIE ? new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
    }
    function calXMLHTTP()
    {
    var szUrl ="http://xxx.com/bbb.asmx?para=nnn"; 
    var oHttp = GetXMLHttpRequest();
    oHttp.open("GET", szUrl, false);
    oHttp.send();
    return oHttp.ResponseText;
    }
    ……或者使用——
    new ActiveXObject("ADODB.Connection")结合new ActiveXObject("ADODB.RecordSet")使用
      

  7.   

    做一个隐藏的button
    <input id=hidbtn runat=server>在后台给listbox1添加属性
    listbox.item.attribute.add("onclick","__doPostBack('hidbtn','')");写上隐藏button的onclick事件
    private hidbtn_onclick(...)
    {
        去数据库搜数据赋值给listbox2;
    }大概是这样,明白吗?
      

  8.   

    前头的都比较复杂哈。
    可以在页面中加入一个iframe,高宽设置为0,当listbox1中值变化时,把变化的值提交到iframe中,在后台通过Form方式得到此值。再查询数据库,得到listbox2中值范围,在后台注册一段脚本函数,循环把这些值添加到listbox2中,实际联动并且无刷新。
      

  9.   

    ls的是asp时代的做法,我也做过,是可以的。
      

  10.   

    尤其感谢一下SassyBoy(web炼金术师)。
      

  11.   

    接收数据是根据跟服务端的接口定义来做的,常规的,用js发送就使用前面那段js;如果是c#,可以使用——
    //***POST 
    ASCIIEncoding encoding=new ASCIIEncoding();
    string reuqesturl = "http://adasd.com/asd.aspx";
    string postdata = "xxxxx";
    byte[] data = encoding.GetBytes(postdata);
    // Prepare web request...
    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(reuqesturl);
    myRequest.Method = "POST";
    //myRequest.ContentType="application/x-www-form-urlencoded";
    myRequest.ContentLength = data.Length;
    Stream newStream = myRequest.GetRequestStream();
    // Send the data.
    newStream.Write(data, 0, data.Length);
    newStream.Close();
    // Get response
    HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
    StreamReader reader = new StreamReader(myResponse.GetResponseStream(),Encoding.Default);
    string content = reader.ReadToEnd();
    Console.WriteLine("Get response from server:"+content);
    myResponse.Close();
    ...//***GET
    // web request
    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(reuqesturl);
    myRequest.Credentials = CredentialCache.DefaultCredentials;
    //myRequest.Method = "GET";
    //myRequest.ContentType="application/x-www-form-urlencoded";
    // Get response
    HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
    string flag = new StreamReader(response.GetResponseStream()).ReadToEnd();
    HttpStatusCode code = response.StatusCode;
    string logtxt = "response status="+code.ToString()+" flag="+flag;
    Console.WriteLine(logtxt);
    ...