title: ASP.NET dynamically add column to Gridview
body: <p>how can I add to GridView dynamically some columns based on condition?</p>
  
  <pre><code>  &lt;asp:gridview id="CustomersGridView" 
      datasourceid="CustomersSource" 
      autogeneratecolumns="true"
      emptydatatext="No data available." 
      runat="server"&gt;
  
      &lt;columns&gt;
        &lt;asp:boundfield datafield="CustomerID" headertext="Customer ID"/&gt;
        &lt;asp:boundfield datafield="CompanyName" headertext="Company Name"/&gt;
        &lt;asp:boundfield datafield="Address" headertext="Address"/&gt;
        &lt;asp:boundfield datafield="City" headertext="City"/&gt;
        &lt;asp:boundfield datafield="PostalCode" headertext="Postal Code"/&gt;
        &lt;asp:boundfield datafield="Country" headertext="Country"/&gt;
      &lt;/columns&gt;
      for(int i; i &lt; length; i++)
        &lt;asp:boundfield datafield="text" headertext="text"/&gt;
    &lt;/asp:gridview&gt;
  </code></pre>