Check for column and bind grid if exists or not
<p>How to bind data to <code>itemtemplate</code> of <code>gridview</code> at <code>RowDataBound</code> event. I am using a gridview and below is the code for that grid view.</p>

<pre><code>&lt;asp:GridView ID="gvCoreUtilization" runat="server" BackColor="White" BorderColor="#cEcFcE"
                    BorderStyle="Solid" BorderWidth="1px" CellPadding="4" ForeColor="Black" OnRowCreated="grdPivot3_RowCreated"
                    AutoGenerateColumns="false" OnRowDataBound="grdCoreUtilization_RowDataBound"&gt;
                    &lt;RowStyle BackColor="#F7F7DE" /&gt;
                    &lt;FooterStyle BackColor="#CCCC99" /&gt;
                    &lt;PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" /&gt;
                    &lt;SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" /&gt;
                    &lt;HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" /&gt;
                    &lt;AlternatingRowStyle BackColor="White" /&gt;
                    &lt;Columns&gt;
                        &lt;asp:TemplateField&gt;
                            &lt;ItemTemplate&gt;
                                &lt;asp:Label ID="lblRoleID" Text='&lt;%#Eval("RoleId") %&gt;' runat="server" Visible="false"&gt;&lt;/asp:Label&gt;
                            &lt;/ItemTemplate&gt;
                        &lt;/asp:TemplateField&gt;
                        &lt;asp:TemplateField&gt;
                            &lt;HeaderTemplate&gt;
                                SupervisorName
                            &lt;/HeaderTemplate&gt;
                            &lt;ItemTemplate&gt;
                                &lt;asp:Label ID="lblSupervisorName" Text='&lt;%#Eval("SupervisorName") %&gt;' runat="server"&gt;&lt;/asp:Label&gt;
                            &lt;/ItemTemplate&gt;
                        &lt;/asp:TemplateField&gt;
                        &lt;asp:TemplateField&gt;
                            &lt;HeaderTemplate&gt;
                                UserECode
                            &lt;/HeaderTemplate&gt;
                            &lt;ItemTemplate&gt;
                                &lt;asp:Label ID="lblUserECode" Text='&lt;%#Eval("UserECode") %&gt;' runat="server"&gt;&lt;/asp:Label&gt;
                            &lt;/ItemTemplate&gt;
                        &lt;/asp:TemplateField&gt;
                        &lt;asp:TemplateField&gt;
                            &lt;HeaderTemplate&gt;
                                UserName
                            &lt;/HeaderTemplate&gt;
                            &lt;ItemTemplate&gt;
                                &lt;asp:Label ID="lblUserName" Text='&lt;%#Eval("UserName") %&gt;' runat="server"&gt;&lt;/asp:Label&gt;
                            &lt;/ItemTemplate&gt;
                        &lt;/asp:TemplateField&gt;
                        &lt;asp:TemplateField&gt;
                            &lt;HeaderTemplate&gt;
                                Designation
                            &lt;/HeaderTemplate&gt;
                            &lt;ItemTemplate&gt;
                                &lt;asp:Label ID="lblDesignation" Text='&lt;%#Eval("Designation") %&gt;' runat="server"&gt;&lt;/asp:Label&gt;
                            &lt;/ItemTemplate&gt;
                        &lt;/asp:TemplateField&gt;
                        &lt;asp:TemplateField&gt;
                            &lt;HeaderTemplate&gt;
                                L &amp; D Training%
                            &lt;/HeaderTemplate&gt;
                            &lt;ItemTemplate&gt;
                                &lt;asp:Label ID="lblLDTraining" Text='&lt;%#Eval("L &amp; D Training%") %&gt;' runat="server"&gt;&lt;/asp:Label&gt;
                            &lt;/ItemTemplate&gt;
                        &lt;/asp:TemplateField&gt;
                        &lt;asp:TemplateField&gt;
                            &lt;HeaderTemplate&gt;
                                Non Production%
                            &lt;/HeaderTemplate&gt;
                            &lt;ItemTemplate&gt;
                                &lt;asp:Label ID="lblNonProduction" Text='&lt;%#Eval("Non Production%") %&gt;' runat="server"&gt;&lt;/asp:Label&gt;
                            &lt;/ItemTemplate&gt;
                        &lt;/asp:TemplateField&gt;
                        &lt;asp:TemplateField&gt;
                            &lt;HeaderTemplate&gt;
                                Process Support%
                            &lt;/HeaderTemplate&gt;
                            &lt;ItemTemplate&gt;
                                &lt;asp:Label ID="lblProcessSupport" Text='&lt;%#Eval("Process Support%") %&gt;' runat="server"&gt;&lt;/asp:Label&gt;
                            &lt;/ItemTemplate&gt;
                        &lt;/asp:TemplateField&gt;
                        &lt;asp:TemplateField&gt;
                            &lt;HeaderTemplate&gt;
                                Process Training%
                            &lt;/HeaderTemplate&gt;
                            &lt;ItemTemplate&gt;
                                &lt;asp:Label ID="lblProcessTraining" Text='&lt;%#Eval("Process Training%") %&gt;' runat="server"&gt;&lt;/asp:Label&gt;
                            &lt;/ItemTemplate&gt;
                        &lt;/asp:TemplateField&gt;
                        &lt;asp:TemplateField&gt;
                            &lt;HeaderTemplate&gt;
                                Production%
                            &lt;/HeaderTemplate&gt;
                            &lt;ItemTemplate&gt;
                                &lt;asp:Label ID="lblProduction" Text='&lt;%#Eval("Production%") %&gt;' runat="server"&gt;&lt;/asp:Label&gt;
                            &lt;/ItemTemplate&gt;
                        &lt;/asp:TemplateField&gt;
                        &lt;asp:TemplateField&gt;
                            &lt;HeaderTemplate&gt;
                                System Downtime%
                            &lt;/HeaderTemplate&gt;
                            &lt;ItemTemplate&gt;
                                &lt;asp:Label ID="lblSystemDowntime" Text='&lt;%#Eval("System Downtime%") %&gt;' runat="server"&gt;&lt;/asp:Label&gt;
                            &lt;/ItemTemplate&gt;
                        &lt;/asp:TemplateField&gt;
                        &lt;asp:TemplateField&gt;
                            &lt;HeaderTemplate&gt;
                                Grand Total%
                            &lt;/HeaderTemplate&gt;
                            &lt;ItemTemplate&gt;
                                &lt;asp:Label ID="lblGrandTotal" Text='&lt;%#Eval("Grand Total%") %&gt;' runat="server"&gt;&lt;/asp:Label&gt;
                            &lt;/ItemTemplate&gt;
                        &lt;/asp:TemplateField&gt;
                    &lt;/Columns&gt;
                &lt;/asp:GridView&gt;
</code></pre>

<p>Here i want to remove <code>EVAl</code> for binding the data to <code>itemtemplate</code>. In place of this i want to check weather</p>

<ol>
<li>If all the Column exists in the <code>dataset</code>/<code>Datatable</code> or not which is mentioned in the Gridview.</li>
<li>If all Column exists  then bind that column to appropriate Itemtemplate .</li>
<li>If All column not exist then display and bind only available column and hide the not available column.</li>
</ol>

<p>Query used:-</p>

<pre><code>Select RoleId,SuperVisorName,Userecode,Username,Designation,TimeSpent,ActivityName 
                                from CoreUtilizationForRole1 where roleid=3
</code></pre>

<p>After executing the above query, i am doing a pivot on Activity column from c# and those columns are "L &amp; D Training%","Non Production%","Process Support%","Process Training%","Production%","System Downtime%","Grand Total%" which i am binding on ItemTemplate. </p>
