title: Find label by name and set label text from code behind
body: <p>I want to set label text from code behind.
  Here is my aspx page I have more labels as well like lbl2, lbl3..</p>
  
  <pre><code>&lt;asp:LinkButton ID="btn1" runat="server" onclick="btn1_Click" &gt;
                        &lt;img id="img1" runat="server"  width="195" height="306" alt="slider"&gt;&lt;label id="lb11" runat="server" /&gt;&lt;/asp:LinkButton&gt;
  </code></pre>
  
  <p>In code behind I am truing this</p>
  
  <pre><code>for (int i = 1; i &lt;= dt.Rows.Count; i++)
              {
  Label lbltest = new Label();
                  lbltest = (Label)this.FindControl("lbl" + i.ToString()) as Label; 
                  lbltest.Text = Convert.ToString(dt.Rows[i - 1]["Type"]);
  }
  </code></pre>
  
  <p>But I am getting error:
  Unable to cast object of type 'System.Web.UI.HtmlControls.HtmlGenericControl' to type 'System.Web.UI.WebControls.Label'.
  What should i do ? Please help!!!!! </p>