ITeye博客

遍历页面上的下拉框元素,设置初始值的4种写法

starnc · 2009-04-30 14:51 · .NET · Markdown

            foreach (Control controls in Page.Form.Controls)
            {
               
                if (controls is System.Web.UI.WebControls.DropDownList  )
                {
                    System.Web.UI.WebControls.DropDownList c = (DropDownList)controls;
                    c.Items.Add(new ListItem("所有","所有"));
                }
            }

 

 foreach (Control controls in Page.Form.Controls)
            {
               
                if (controls.GetType()=="System.Web.UI.WebControls.DropDownList"  )
                {
                    System.Web.UI.WebControls.DropDownList c = (DropDownList)controls;
                    c.Items.Add(new ListItem("所有","所有"));
                }
            }

 

 foreach (Control controls in Page.Form.Controls)
            {
               
                if (controls.GetType()== typeof(System.Web.UI.WebControls.DropDownList))
                {
                    System.Web.UI.WebControls.DropDownList c = (DropDownList)controls;
                    c.Items.Add(new ListItem("所有","所有"));
                }
            }

 

foreach (Control controls in Page.Form.Controls)
            {
               
                if (controls.GetType().Equals(typeof(System.Web.UI.WebControls.DropDownList)))
                {
                    System.Web.UI.WebControls.DropDownList c = (DropDownList)controls;
                    c.Items.Add(new ListItem("所有","所有"));
                }
            }

 以上4种写法都可以,我也是主要学习一下typeof和gettype()的用法

评论(2)

  1. #2 楼 · starnc · 2009-05-06 11:08

    lobbychmd writes:

    $('input[type=select]').val('所有') 哈哈

    大哥,能不用jquery不

  2. #1 楼 · lobbychmd · 2009-05-06 09:27

    $('input').val('所有') 哈哈

评论功能维护中,当前仅展示历史评论。