遍历Label 和遍历 DropDownList

动态增加表字段对数据库稳定性有很大影响,那只好来死的了,嘿嘿。

说明:pnlMaterial是容器名,页面中有Label1-Label40, Dropdownlist1-Dropdownlist40,如此之多控件....


  ///
    /// 遍历页面的label并赋值,    ///

    protected void RenameLabel()
    {
        foreach (Control ctr in this.pnlMaterial.Controls)
        {

            if (ctr.GetType().ToString() == "System.Web.UI.WebControls.Label")
            {
                //Response.Write("id:" + ctr.ID+ "   text:" + ((Label)ctr).Text + "
");

                if (ctr.ID.ToString().Length == 6)
                {
                   int LabelId1 = Convert.ToInt32(ctr.ID.Substring(5, 1).ToString().Trim());

                    ((Label)ctr).Text = BLL.EDI.EDIType.GetTypeName(LabelId1);
                }
              
                if (ctr.ID.ToString().Length == 7)
                {
                   int LabelId2 = Convert.ToInt32(ctr.ID.Substring(5, 2).ToString().Trim());

                    ((Label)ctr).Text = BLL.EDI.EDIType.GetTypeName(LabelId2);

                }
                
            }

        }

    }


   ///
    /// 遍历dropdownlist赋值
    ///

    protected void SetDropDownListValue()
    {
        foreach (Control ctr in this.pnlMaterial.Controls)
        {

            if (ctr.GetType().ToString() == "System.Web.UI.WebControls.DropDownList")
            {
                //Response.Write("id:" + ctr.ID + "   text:" + ((DropDownList)ctr).DataTextField.ToString() + "
");

                if (ctr.ID.ToString().Length == 13)
                {
                    int LabelId1 = Convert.ToInt32(ctr.ID.Substring(12, 1).ToString().Trim());

                    ((DropDownList)ctr).DataSource = BLL.EDI.EDIMaterial.List(LabelId1);

                    ((DropDownList)ctr).DataValueField = "mName";

                    ((DropDownList)ctr).DataTextField = "mCode";

                    ((DropDownList)ctr).DataBind();
                }

                if (ctr.ID.ToString().Length == 14)
                {
                    int LabelId2 = Convert.ToInt32(ctr.ID.Substring(12, 2).ToString().Trim());

                    ((DropDownList)ctr).DataSource = BLL.EDI.EDIMaterial.List(LabelId2);

                    ((DropDownList)ctr).DataValueField = "mName";

                    ((DropDownList)ctr).DataTextField = "mCode";

                    ((DropDownList)ctr).DataBind();
                }

            }

        }

    }

上一篇: 存储过程实现对MS SQL表结构的操作
下一篇: 遍历页面控件的几种方法
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 0 | 引用: 0 | 查看次数: 12719
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 30 字 | UBB代码 关闭 | [img]标签 关闭