title: How to build a GridView like DataBound Templated Custom ASP.NET Server Control
body: <p>I am trying to develop a very simple templated custom server control that resembles GridView. Basically, I want the control to be added in the .aspx page like this:</p>
  
  <pre><code>    &lt;cc:SimpleGrid ID="SimpleGrid1" runat="server"&gt;
           &lt;TemplatedColumn&gt;ID: &lt;%# Eval("ID") %&gt;&lt;/ TemplatedColumn&gt;
           &lt;TemplatedColumn&gt;Name: &lt;%# Eval("Name") %&gt;&lt;/ TemplatedColumn&gt;
           &lt;TemplatedColumn&gt;Age: &lt;%# Eval("Age") %&gt;&lt;/ TemplatedColumn&gt;
      &lt;/cc:SimpleGrid&gt;
  </code></pre>
  
  <p>and when providing the following datasource: </p>
  
  <pre><code>    DataTable table = new DataTable();
      table.Columns.Add("ID", typeof(int));
      table.Columns.Add("Name", typeof(string));
      table.Columns.Add("Age", typeof(int));
  
      table.Rows.Add(1, "Bob", 35);
      table.Rows.Add(2, "Sam", 44);
      table.Rows.Add(3, "Ann", 26);
  
      SimpleGrid1.DataSource = table;
      SimpleGrid1.DataBind();
  </code></pre>
  
  <p>the result should be a HTML table like this one.</p>
  
  <pre><code> -------------------------------
   | ID: 1 | Name: Bob | Age: 35 |
   -------------------------------
   | ID: 2 | Name: Sam | Age: 44 |
   -------------------------------
   | ID: 3 | Name: Ann | Age: 26 |
   -------------------------------
  </code></pre>
  
  <p>The main problem is that I cannot define the TemplatedColumn. When I tried to do it like this ...</p>
  
  <pre><code>    private ITemplate _TemplatedColumn;
      [PersistenceMode(PersistenceMode.InnerProperty)]
      [TemplateContainer(typeof(TemplatedColumnItem))]
      [TemplateInstance(TemplateInstance.Multiple)] 
      public ITemplate TemplatedColumn
      {
          get { return _TemplatedColumn; }
          set { _TemplatedColumn = value; }
      }
  </code></pre>
  
  <p>.. and subsequently instantiate the template in the CreateChildControls I got the following result which is not what I want:</p>
  
  <pre><code> -----------
   | Age: 35 |
   -----------
   | Age: 44 |
   -----------
   | Age: 26 |
   -----------
  </code></pre>
  
  <ul>
  <li>I know that what I want to achieve is pointless and that I can use DataGrid to achieve it, but I am giving this very simple example because if I know how to do this I would be able to develop the control that I need. Thank you.</li>
  </ul>