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
foreach(ListItem _item in seljobfamily.Items)
{
_item.Selected=true;
}
可以按saucer的方法去做,也可以使用 web服务器空件
{
//在这里加上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]);
}
}}
{
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]);
}
}}