they are server controls, they don't know you have done something to them on the client side, either use hidden controls to pass the changes back, or before you submit, select all options in both HtmlSelects and use Request.Form.GetValues("seljobfamily") and Request.Form.GetValues("jobfamily") to refill your HtmlSelect

解决方案 »

  1.   

    可以多项同时选择吗?
    foreach(ListItem _item in seljobfamily.Items)
    {
      _item.Selected=true;
    }
      

  2.   

    对不起,看错了!
    可以按saucer的方法去做,也可以使用 web服务器空件
      

  3.   

    思归大哥,那是不是就说我用 javascript 实现不了这个功能了,因为他是服务器端控件,他并不知道你在客户端对他干了什么,那我只能在服务器端实现这个功能了?那这可麻烦透了,有很多功能我都得放弃 javascript 吗?
      

  4.   

    思归大哥,是不是这样,可以用 javascript 实现这个功能,只不过是我在按 button1 的时候,多做一点工作,如:private void Button1_Click(object sender, System.EventArgs e)
    {
      //在这里加上Request.Form.GetValues("seljobfamily") 
      //然后下面的代码在使用Request 过来的值。
     //可是这地方俱体要怎么写呢?HtmlSelect[] hs = new HtmlSelect[]{seljobfamily, selindustry,sellocation };
    string[] skey = {"职业类型", "所属行业", "工作地点"};
    string[] slist = new string[3];
    for(int i=0; i < slist.Length; i++)
    slist[i] = "";for (int i=0; i < hs.Length; i++)
    {
    foreach (ListItem li in hs[i].Items)
    {
    if (li.Selected)
    if (li.Value == "0")
    {
    slist[i] = "";
    break;
    }
    else
    slist[i] += (slist[i].Length> 0? " OR " : "") + String.Format(" {0} LIKE '%{1}%' ", skey[i], li.Value.Replace("'","''"));
    }if ( slist[i] != "")
    {
    slist[i] +=  String.Format(" OR {0} = '不要求' ", skey[i]);
    }
    }}
      

  5.   

    you can still do it on the client side with javascript, but you have to understand this is HTTP and there is client/server differenceprivate void Button1_Click(object sender, System.EventArgs e)
    {
       string[] jobs = Request.Form.GetValues("seljobfamily");
       string[] industries = Request.Form.GetValues("selindustry");
       string[] locations = Request.Form.GetValues("sellocation");string[][] hs = new string[][]{jobs,industries,locations};
    string[] skey = {"职业类型", "所属行业", "工作地点"};
    string[] slist = new string[3];
    for(int i=0; i < slist.Length; i++)
    slist[i] = "";for (int i=0; i < hs.Length; i++)
    {
    foreach (string s in hs[i])
    {
    if (s == "0")
    {
    slist[i] = "";
    break;
    }
    else
    slist[i] += (slist[i].Length> 0? " OR " : "") + String.Format(" {0} LIKE '%{1}%' ", skey[i], s.Replace("'","''"));
    }if ( slist[i] != "")
    {
    slist[i] +=  String.Format(" OR {0} = '不要求' ", skey[i]);
    }
    }}
      

  6.   

    这句话通不过啊foreach (ListItem li in hs[i].Items)编译时出错:C:\Inetpub\wwwroot\guan_isea\Advanced_search.aspx.cs(171): “System.Array”并不包含对“Items”的定义
      

  7.   

    make sure the names for the HtmlSelect are correct:"seljobfamily", "selindustry", "sellocation"otherwise, you will get a NullReferenceException