title: If you're using a generic DataGrid, is there a way to hide specific fields?
body: <p>I've got some code like this:</p>
  
  <h1>asp.net</h1>
  
  <pre><code>&lt;div id="divGrid" style='width:920px; height:430px; overflow:auto'&gt;
      &lt;asp:DataGrid ID="DataGrid_AuditSearch" runat="server"
      AllowPaging="True" AllowSorting="True" CellPadding="4" ForeColor="#333333" GridLines="None"
      OnCancelCommand="DataGrid_AuditSearch_CancelCommand" 
      OnUpdateCommand="DataGrid_AuditSearch_UpdateCommand" 
      OnEditCommand="DataGrid_AuditSearch_EditCommand"&gt;
          &lt;AlternatingItemStyle Font-Bold="False" Font-Italic="False" 
             Font-Overline="False" Font-Strikeout="False" Font-Underline="False" /&gt;
          &lt;EditItemStyle BackColor="#999999" Font-Bold="False" Font-Italic="False" 
             Font-Overline="False" Font-Strikeout="False" Font-Underline="False" /&gt;
          &lt;FooterStyle BackColor="#5D7B9D" Font-Bold="False" Font-Italic="False" 
             Font-Overline="False" Font-Strikeout="False" Font-Underline="False" /&gt;
          &lt;HeaderStyle BackColor="#5D7B9D" Font-Bold="False" Font-Italic="False" 
             Font-Overline="False" Font-Strikeout="False" Font-Underline="False" /&gt;
          &lt;PagerStyle BackColor="#5D7B9D" Font-Bold="False" Font-Italic="False" 
             Font-Overline="False" Font-Strikeout="False" Font-Underline="False" /&gt;
          &lt;SelectedItemStyle BackColor="#E2DED6" Font-Bold="False" Font-Italic="False" 
             Font-Overline="False" Font-Strikeout="False" Font-Underline="False" /&gt;
          &lt;Columns&gt;
              &lt;asp:EditCommandColumn ButtonType="PushButton" CancelText="Cancel" 
                 EditText="Select" UpdateText="Update"&gt;&lt;/asp:EditCommandColumn&gt;
          &lt;/Columns&gt;
  
      &lt;/asp:DataGrid&gt;
      &lt;asp:Label ID="lblEmpty" runat="server" Visible="false" Style="font-weight:bold; font-size:large;"&gt;&lt;/asp:Label&gt;
  &lt;/div&gt; 
  </code></pre>
  
  <h1>C#:</h1>
  
  <pre><code>public void Show_Data(int AuditID)
  {
      try
      {
          OracleConnection conn = GetConnection();
          {
              conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnCST"].ToString();
  
              OracleCommand cmd3 = new OracleCommand();
              cmd3.Connection = conn;
  
              sqlquery2 = "SELECT * from MyTable";
  
              cmd3.CommandText = sqlquery2;
  
              var SearchAdapter = new OracleDataAdapter(cmd3);
              var ds = new DataSet();
              SearchAdapter.Fill(ds);
  
              // Perform the binding.
              DataGrid_AuditSearch.DataSource = ds;
              DataGrid_AuditSearch.DataBind();
  
              if (DataGrid_AuditSearch.Items.Count &lt; 1)
              {
                  lblEmpty.Visible = true;
                  lblEmpty.Text = "There is no data to display";
              }
              else
              {
                  lblEmpty.Visible = false;
              }
  
              //DataGrid_AuditSearch.Columns[3].Visible = false;
              //DataGrid_AuditSearch.Columns[1].Visible = false;
          }
      }
      catch (Exception ex)
      {
          Response.Write(ex.Message);
      }
  
  }
  </code></pre>
  
  <p>Pretty boring, generic stuff.  All fields are generated based on the binding.</p>
  
  <p>However, there are 2 fields I want to be able to access (because I need the data), but I don't want to show on the screen.  Is there a way to do this "dynamically"?  In that, I don't want to have to explicitly name all the fields I want to display and in what order.  </p>
  
  <p>I tried adding this after the DataBind command, but it didn't do anything:</p>
  
  <pre><code>DataGrid_AuditSearch.Columns[3].Visible = false;
  DataGrid_AuditSearch.Columns[1].Visible = false;
  </code></pre>