查找主页内和可折叠面板内的动态创建的网格视图

时间:2016-04-27 14:31:46

标签: c# asp.net gridview

这肯定是前进了43步。通过第一个gridview用户控件创建。但无论如何。我所拥有的是动态创建的网格视图。整个页面构建在母版页上,每个gridview都位于其自己动态创建的可折叠面板中。

现在我需要遍历每个gridview的行。问题是我在后面的代码中找不到它们。我尝试了各种递归函数,没有运气。所以我不知道我在做什么。

以下是我用来创建网格视图和面板的代码。

            int x = 1;

            while (sqlReader.Read())
            {
                // Create Panel Header
                Panel PH = new Panel();
                PH.ID = "PH" + Convert.ToString(x);
                PH.CssClass = "cheader";

                // Add Label inside header panel to display text
                Label lblPH = new Label();
                lblPH.ID = "lblPH" + Convert.ToString(x);
                lblPH.Text = sqlReader["Category"].ToString();
                PH.Controls.Add(lblPH);

                //Create Body Panel
                Panel PB = new Panel();
                PB.ID = "PB" + Convert.ToString(x);

                // Create CollapsiblePanelExtender
                CollapsiblePanelExtender CPE = new CollapsiblePanelExtender();
                CPE.ID = "CPE" + Convert.ToString(x);
                CPE.TextLabelID = lblPH.ID;
                CPE.ExpandControlID = PH.ID;
                CPE.CollapseControlID = PH.ID;
                CPE.TargetControlID = PB.ID;
                CPE.ScrollContents = false;
                CPE.Collapsed = true;
                CPE.ExpandDirection = CollapsiblePanelExpandDirection.Vertical;
                CPE.SuppressPostBack = true;

                this.UpdatePanel1.ContentTemplateContainer.Controls.Add(PH);
                this.UpdatePanel1.ContentTemplateContainer.Controls.Add(PB);
                this.UpdatePanel1.ContentTemplateContainer.Controls.Add(CPE);

                //*** This is loading the gridview user control

                EPOGVSurvey ctl = Page.LoadControl("EPOGVSurvey.ascx") as EPOGVSurvey;
                ctl.MyParameterValue = sqlReader["Category"].ToString();
                ctl.ID = "CAT" + x;

                PB.Controls.Add(ctl);
                PB.CssClass = "cdata";

                x++;
            }

            sqlReader.Close();

尝试阅读gridviews的代码

GridView gv = FindControlRecursive(Page, "Gridview" + i) as GridView;
if (gv != null)
{
    foreach (GridViewRow row in gv.Rows)
    {    

0 个答案:

没有答案