title: How to hide a column in a DataGrid?
body: <p>I need to hide the <code>RevToDate</code> column in the <code>DataGrid</code> for any user who is not admin. How do I hide only this column?</p>
  
  <pre><code> &lt;asp:DataGrid runat="server" CssClass="tblResults" OnItemDataBound="dgList_ItemCreated" AllowSorting="true" OnSortCommand="dgCustomer_Sort" ID="dgCustomers" DataKeyField="ID" AutoGenerateColumns="false"&gt;
              &lt;HeaderStyle CssClass="tblResultsHeader" /&gt;
              &lt;AlternatingItemStyle BackColor="#EEEEEE" /&gt;
              &lt;Columns&gt;
                  &lt;asp:HyperLinkColumn ItemStyle-CssClass="loading" DataNavigateUrlFormatString="Customer.aspx?CustID={0}" DataNavigateUrlField="ID" DataTextField="AccountCode" HeaderText="A/C Code" SortExpression="AccountCode"&gt;&lt;/asp:HyperLinkColumn&gt;
                  &lt;asp:BoundColumn DataField="CurrencyDesc" HeaderText="Currency" SortExpression="CurrencyDesc"&gt;&lt;/asp:BoundColumn&gt;
                  &lt;asp:BoundColumn DataField="RevToDate" HeaderText="Rev To Date (Net)" SortExpression="RevToDate"&gt;&lt;/asp:BoundColumn&gt;
                  &lt;asp:BoundColumn DataField="CreditLimitAmount" HeaderText="Credit Limit" SortExpression="CreditLimitAmount"&gt;&lt;/asp:BoundColumn&gt;
                  &lt;asp:BoundColumn DataField="DiscountReviewDate" HeaderText="Discount Review Date" SortExpression="DiscountReviewDate" Visible="false"&gt;&lt;/asp:BoundColumn&gt;
              &lt;/Columns&gt;
   &lt;/asp:DataGrid
  </code></pre>
  
  <p>I'm using this code to hide certain items:</p>
  
  <pre><code> if (!CurrentUser.IsInRole("Admin"))
      {
          btnDelete.Visible = false;
          btnUpload2.Visible = false;
      }
  </code></pre>
  
  <p>But I am not sure how to hide the column. I can't set Visible to false in the CSS because it will hide the column from all users. </p>