要实现的要求如下:
有一个DropDownList框,通过下拉框中选择值来改变CheckBoxList绑定的项。选择CheckBoxList里的值后,保存选中的值在A变量,取消了选中的值,移出A变量里对应的值,当用户重新选择DropDownList框值,A变量的值不能清空,继续追加用户选择的值。直到用户点击确定按钮,才把A变量的值保存到数据库。应该怎么实现?

解决方案 »

  1.   

    CheckBoxList选择值如果不想用SelectedIndexChange事件刷新页面的话可以用JS控制 把所有选择的值用","连接拼到一个hindden的input中,没有选中就string.Replace(","+"选中的值","")每次DropDownList的SelectedIndexChange重新绑定CheckBoxList时候if(ViewState["selstr"]==null)
         ViewState["selstr"]=Request["input的id"];
    else
          ViewState["selstr"]=ViewState["selstr"].ToString()+","+Request["input的id"];
    按钮的事件
    string aa ="";
    if(ViewState["selstr"]==null)
         aa=Request["input的id"];
    else
         aa=ViewState["selstr"].ToString()+","+Request["input的id"];  
      

  2.   

    生成出来的页面代码如下:<tr>
                    <td>
                        <input id="CheckBoxList1_0" type="checkbox" name="CheckBoxList1$0" /><label for="CheckBoxList1_0">信息技术经理·信息技术主管</label></td>
                    <td>
                        <input id="CheckBoxList1_1" type="checkbox" name="CheckBoxList1$1" /><label for="CheckBoxList1_1">信息技术专员</label></td>
                    <td>
                        <input id="CheckBoxList1_2" type="checkbox" name="CheckBoxList1$2" /><label for="CheckBoxList1_2">产品经理·品牌经理</label></td>
                </tr>
                <tr>
                    <td>
                        <input id="CheckBoxList1_3" type="checkbox" name="CheckBoxList1$3" /><label for="CheckBoxList1_3">项目经理·项目主管</label></td>
                    <td>
                        <input id="CheckBoxList1_4" type="checkbox" name="CheckBoxList1$4" /><label for="CheckBoxList1_4">项目执行·协调人员</label></td>
                    <td>
                        <input id="CheckBoxList1_5" type="checkbox" name="CheckBoxList1$5" /><label for="CheckBoxList1_5">架构师</label></td>
                </tr>
    怎么用JS控制 把所有选择的值用","连接啊,能不能给点代码,分不够可以加的...
      

  3.   


     function selectstr(){
     var  tmpstr;
     for(int i=0;i<document.Form1.CheckBoxList1.length;i++)
     {
      if(!document.Form1.CheckBoxList1.options[i].selected){
        if(tmpstr.indexOf(document.Form1.CheckBoxList1.options[i].text)>0)
        {
         tmpstr.replace(","+document.Form1.CheckBoxList1.options[i].text,"");
        }
        }
      else
       {
         if(tmpstr.indexOf(document.Form1.CheckBoxList1.options[i].text)<0)
          {
            tmpstr +=","+document.Form1.CheckBoxList1.options[i].text;
          }
       }
     }  document.Form1.selectinput.value =tmpstr;
    }//PageLoad中
     CheckBoxList1.Attributes.Add("onclick","selectstr()");
    以上代码未经测试其实还有更取巧的办法...
    你可以按照DropDownList的item数事先将 item.Count 个CheckBoxList绑定在页面中
    用js控制,选择哪项就显示哪个CheckBoxList提交的时候,循环所有的CheckBoxList的选中就可以了。
      

  4.   

    lz是不是要让所有的选中了的数据一起查进数据库?
    aspx页面将id绑定到CheckBox 的CssClass 
    上面写了很js方法
         foreach (DataListItem dlia in DataList1.Items)
         {
            CheckBox cha = (CheckBox)(dlia.FindControl("CheckBox1"));
            
              if(cha.Checked)
                 {
                      id=   cha.CssClass
                 }
               
          }