我在一个repeater 中绑定的有 二列 一列是checkBox 另一列是dropDownList
初始化时dropDownList是隐藏的当checkBox 为true 时,就显示dropDownList 
问题就在这里出现了,当我点击 checkBox 为true 时,显示dropDownList 然后我选中值,、
点击第二个checkBox 的时候,dropDownList 之前被选中的值被刷新掉了,又是最初始的默认值, 
而我想要不是默认值,是选中后的值。。

解决方案 »

  1.   

    这个涉及到页面的生命周期的问题,可能你是先给dropDownList 初始化了,再添加到页面中去的,这样就不能保存dropDownList 的viewstate,刷新后就复原了
      

  2.   

    回传了 你用的是服务器控件。那autopostback 属性设置为flase
      

  3.   

    用AJAX无刷新技术吧!把他们都包起来!
      

  4.   

    点击第二个checkBox ,又触发了dropDownList 的绑定事件,重新赋值了你查看下,应该是这个问题。
      

  5.   

    如果把checkBox 的autopostback 设为FALSE 的话那就不能激发这个事件而让dropDownList 显示了。1楼说的对,我可能是这个原因 dropDownList 中是一个枚举值,当 checkBox 为true 时,这时候就显示dropDownList 并调用枚举添加该项值,每次都被刷新掉。,不知道可以解决不?
      

  6.   

    你可以把它们的状态保存到ViewState中,然后在点击checkBox时,双击这个控件有个事件,在这个事件里根据你的viewState中的状态重新绑定一下
      

  7.   

    是不是scriptManager 这个标签
      

  8.   

    大伙帮我看下了,在下真解决不了呀!! private void AddListItem(DropDownList ddlType)
            {
                //加之前先清空
                ddlType.Items.Clear();            ListItem listIgnore = new ListItem();
                listIgnore.Value = "忽略";
                ddlType.Items.Add(listIgnore);
                string[] valueType = Enum.GetNames(typeof(DATACONFIG.ValueType));
                for (int i = 0; i < valueType.Length; i++)
                {
                    ListItem listItem = new ListItem();
                    listItem.Value = valueType[i];
                    ddlType.Items.Add(listItem); //这个LISTitem 中一共有3个项
                }
            } public void Check_Clicked(object sender, EventArgs e)
            {
                foreach (RepeaterItem Item in rptSource.Items)
                {
                    CheckBox ck = (CheckBox)Item.FindControl("ck_isValue");
                    DropDownList ddlType = (DropDownList)Item.FindControl("ddlType");
                    TextBox txtValue = (TextBox)Item.FindControl("txtValue");
                           ddlType.Visible = true;
                            AddListItem(ddlType);
           }
                }
      

  9.   

    每次选中 ChceckBox 为true时,调用这个方法添加 AddListItem(ddlType); 每次刷新后的默认值都为忽略, 这样很不好,很是郁闷。