动态控件在HTML中使用FindControl()为空

时间:2018-06-20 09:43:35

标签: html

我正在html页面上创建动态控件(标签),然后将值分配给每个标签,但是当我在页面上找到控件时(此代码的最后两行),它显示为null。 你能帮我吗?

           DataTable dtdata = new DataTable();
            sda.Fill(dtdata);
            StringBuilder strNom = new StringBuilder(); ;
            for (int i = 0; i < dtState.Rows.Count; i++)
            {

                statename = dtState.Rows[i]["ST_NAME"].ToString();
                strNom.Append("<div class='col-md-3 col-sm-4 col-xs-12 text-center search-box-height'>");
                strNom.Append(" <table border='1' style='width:100%;border:solid;border-collapse:collapse' >");


                strNom.Append("  <tr><td rowspan='6' width=6%><asp:Label ID=" + "test1" + " runat='server'>" + Convert.ToInt32(i + 1) + " </asp:Label></td>");
                strNom.Append("  <td rowspan='6' width=40%><asp:Label ID='lbl" + statename + "' runat='server'>" + dtState.Rows[i]["ST_NAME"].ToString() + "  </asp:Label></td>");
              //  strNom.Append("  <td rowspan='6' width=40%>"+lblDriver+" </asp:Label></td>");
                strNom.Append("  <td rowspan='6' width=15%><asp:Label ID='lbl" + statename + "totalcount' runat='server'>" + totalcount + "  </asp:Label></td>");
                strNom.Append("   <td rowspan='1'> <asp:Label ID='lbl" + statename + "domestic' runat='server'> " + "Domestic Help(" + domestic + ")" + " </asp:Label></td></tr>");
                strNom.Append("  <tr> <td rowspan='1'> <asp:Label ID='lbl" + statename + "Driver' runat='server'>" + "Driver(" + Driver + ")" + "  </asp:Label></td></tr>");
                strNom.Append("  <tr> <td rowspan='1'> <asp:Label ID='lbl" + statename + "Employee' runat='server'>" + "Employee(" + Employee + ")" + "  </asp:Label></td></tr>");
                strNom.Append("  <tr> <td rowspan='1'> <asp:Label ID='lbl" + statename + "Nurse' runat='server'>" + "Nurse(" + Nurse + ")" + "  </asp:Label></td></tr>");
                strNom.Append("  <tr> <td rowspan='1'> <asp:Label ID='lbl" + statename + "Self' runat='server'>" + "Self(" + Self + ")" + "  </asp:Label></td></tr>");
                strNom.Append("  <tr> <td rowspan='1'> <asp:Label ID='lbl" + statename + "Tenant' runat='server'>" + "Tenant(" + Tenant + ")" + "  </asp:Label></td></tr>");
                strNom.Append(" </table></div>");
            }

            divReport.InnerHtml = strNom.ToString();
            ViewState["divReport"] = strNom;
            Label lbldriver = (Label)divReport.FindControl("lblASSAMDriver");
            lbldriver.Text="abc";

0 个答案:

没有答案