title: Adding WebUserControl To Gridview in asp.net
body: <p>I want to add a webusercontol which contains a textbox and a label to the gridview control. I am binding a gridview with a datatable dynamically.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>@ Register Src="CompareBox.ascx" TagName="CompareBox" TagPrefix="objCompareBox" %&gt;&lt;br&gt;
  &lt;asp:GridView ID="grdfoneBoxContainer" runat="server"&gt;
           &lt;Columns&gt;&lt;br&gt;
                &lt;asp:TemplateField HeaderText="User control"&gt; &lt;br&gt;
                    &lt;ItemTemplate&gt;&lt;br&gt;
                        &lt;objCompareBox:CompareBox ID="CompareBoxCol1" runat="server"/&gt;&lt;br&gt;
                    &lt;/ItemTemplate&gt;&lt;br&gt;
                &lt;/asp:TemplateField&gt;&lt;br&gt;
           &lt;/Columns&gt;&lt;br&gt;
  &lt;/asp:GridView&gt;&lt;br&gt;
  
      DataTable dt = new DataTable();
      dt.Columns.Add("uc1");
      dt.Columns.Add("uc2");
      dt.Columns.Add("uc3");
      dt.Columns.Add("uc4");
  
      CompareBox objCompareBox = new CompareBox();
      objCompareBox.txt= "World";
      objCompareBox.lbl = "Hello";
  
      dt.Rows.Add(objCompareBox, objCompareBox, objCompareBox, objCompareBox);
      dt.Rows.Add(objCompareBox, objCompareBox, objCompareBox, objCompareBox);
      dt.Rows.Add(objCompareBox, objCompareBox, objCompareBox, objCompareBox);
      dt.Rows.Add(objCompareBox, objCompareBox, objCompareBox, objCompareBox);
  
  
      grdfoneBoxContainer.DataSource = dt;
      grdfoneBoxContainer.DataBind();
  </code></pre>
  
  <p>txt &amp; lbl are two properties that are declared in WebUserControl but it's giving object reference error . </p>
  
  <p>Thanks,</p>