现在的位置: 首页 > 综合 > 正文

C#获取网页上的控件信息

2013年07月14日 ⁄ 综合 ⁄ 共 951字 ⁄ 字号 评论关闭
本人从dataset中获取一些列信息,通过某个字段来判断网页上是否有与之对应的Label控件,然后把这个字段数据赋值给这个Label控件。

         //通过循环得到网页上的label
        if (ds.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                //通过循环得到网页上的label
                foreach (Control c in Page.Controls)
                {
                    foreach (Control childc in c.Controls)
                    {
                        if (childc is Label)
                        {
                            if (((Label)childc).ID.Length > 4)
                            {
                              //判断,截取Label控件信息进行判断
                                if (((Label)childc).ID.Substring(3, 3) == ds.Tables[0].Rows[i]["r_gwdm"].ToString())
                                {
                                    ((Label)childc).Text = ds.Tables[0].Rows[i]["sl"].ToString();//赋值
                                }
                            }
                        }
                    }
                }
            }
        }

抱歉!评论已关闭.