各位好,小弟向大家请教个问题,是这样的,我的页面上有上百个DropDownList控件,名子不是DropDownList1,DropDownList2.......,而是由我自己定义的其它名称,怎样用一个for语句,把这上百个DropDownList的所选择项的值用一个字符串把它加起来?

解决方案 »

  1.   

    客户端脚本.
    DDLArray[]=document.GetElementByTag("### ")
      

  2.   

    脚本 var a=document.GetElementByTag("DropDownList");
      

  3.   

    public static Control GetPostBackControl(Page page)
    ...{
        Control control = null;    string ctrlname = page.Request.Params.Get("__EVENTTARGET");
        if (ctrlname != null && ctrlname != string.Empty)
        ...{
            control = page.FindControl(ctrlname);
        }
        else
        ...{
            foreach (string ctl in page.Request.Form)
            ...{
                Control ddl = page.FindControl(ctl);
                if (ddl is System.Web.UI.WebControls.DropDownList)
                ...{
                    control = c;
                    break;
                }
            }
        }
        return control;
    }
      

  4.   


            foreach (Control ctrl in this.Page.Controls)
            {
                foreach (Control ctl in ctrl.Controls)
                {
                    if (ctl.GetType().Name == "DropDownList")
                    {
                        DropDownList dr = new DropDownList();
                        dr = (DropDownList)this.FindControl(ctl.ID);
                        dr.Items.Add(new ListItem("0", "请选择3"));
                                        }
                    
                }
            }修改下就可以
      

  5.   


            foreach (Control myCl in this.Page.Controls)
            {
                if (myCl.GetType().ToString() == "System.Web.UI.WebControls.DropDownList")
                {
                    //do something
                }
            }