我写了个页面...用repter与checkbox组合.绑定了部门对应的人员.  接下来是想获取选定的值.(值的获取我写好了..) 碰到的问题是我这些值无法在button onclick的事件中传递出去..!~我把代码贴出来..麻烦大家给分析分析..!~谢谢!
  public void  chos (RepeaterItemEventArgs e)
    {
        //string[] person ={ };
        ArrayList arr = new ArrayList();//定义数组,存放员工工号
        CheckBoxList ck = e.Item.FindControl("ch_renyuan") as CheckBoxList;//从repter中获得checkboxList的ID
        for (int i=0; i < ck.Items.Count; i++)//循环获得checkboxlist被选中的值
        {
            if (ck.Items.Count > 0)//判断是否有选择
            {
                if (ck.Items[i].Selected == true)//判断哪个被选择
                {
                   // person += ck.Items[i].Value.ToString();
                    arr.Add(ck.Items[i].Value);
                }
            }
            else
            {
                Response.Write("<script>alert('请选择收件人!!')</script>");
            }
        }

解决方案 »

  1.   

        protected void btn_chok_Click(object sender, EventArgs e)
        {
         
        }我在这里用什么代码可以 使用 chos?
      

  2.   

      public void  chos (RepeaterItemEventArgs e)
    你这个不是button的click处理程序吧?
      

  3.   

    这些值无法在button onclick的事件中传递出去?
    什么意思?
    你下传递到哪?
      

  4.   

    你应该在button处理程序里:
    循环查找repeater的rows里的checkbox有没选中吧?
    foreach (repeateritem item in repeater1.items)
    {
    checkbox chk= (checkbox)item.findcontrol("checksingle");
    if(chk.checked)
    {。
      

  5.   

    foreach (repeateritem item in repeater1.items)
    {
        CheckBoxList ck =item .FindControl("ch_renyuan") as CheckBoxList;
         for (int i=0; i < ck.Items.Count; i++)
            {
                if (ck.Items[i].Selected)
                  {
                      arr.Add(ck.Items[i].Value);
                 }
           }
    }
      

  6.   

       我用了...可是无法获得chk.datavalue..?
      

  7.   


     谢谢..可以循环..也能获得值...但是判断下来不管是选中还是未选中都ck.Items[i].Selected 的值都是false !~~不知道为什么...!
      

  8.   

    是不是你回发后重新获取并绑定了数据?是的话checked当然为false
      

  9.   


      就是chk.然后后面就没有datavalue这个选项...!~自己写上去.NET也不理我..!~55555
      

  10.   

      protected void btn_chok_Click(object sender, EventArgs e)
        {
            ArrayList arr = new ArrayList();//定义数组,存放员工工号
            foreach (RepeaterItem item in rpbumen.Items)
            {
                CheckBoxList ck = item.FindControl("ch_renyuan") as CheckBoxList;
                for (int i = 0; i < ck.Items.Count; i++)
                {
                    if (ck.Items[i].Selected)
                    {
                        arr.Add(ck.Items[i].Value);
                        Response.Write("<script>alert('" + arr + "')</script>");
                    }
                }
            }
        }没有重新绑定啊..!~这个是代码?
      

  11.   

    你在pageload里有没把获取和绑定数据的代码放到(!IsPostback)里?
      

  12.   


    protected void rptQuestionList_ItemCommand(object source, RepeaterCommandEventArgs e)
            {
                if (e.CommandName == "toDetail")
                {
                    int itemIndex = e.Item.ItemIndex;
                    this.hfldRepIndex.Value = itemIndex.ToString();
                }
            }LZ试下
    用repeater的这个事件处理~