title: get values from Hidden cells in gridview asp.net c# using onrowdatabound
body: <p>(eg to set rowcolor based on hidden value)</p>
  
  <p>if you have a gridview which has hidden cells like this</p>
  
  <pre><code>&lt;asp:GridView ID="Timeevents" runat="server" 
          OnRowDataBound="Timeevents_RowDataBound"
          OnRowCommand = "Timeevents_RowCommand"
          AutoGenerateColumns="False"&gt; 
          &lt;columns&gt;
          &lt;asp:BoundField DataField="CaseID" HeaderText="CaseID" Visible = "False" /&gt;
          &lt;asp:BoundField DataField="caseworkerID" HeaderText="CwID" Visible = "False" /&gt;
          &lt;asp:BoundField DataField="EventTypeID" HeaderText="EvTypeID" Visible = "False" /&gt;
          &lt;asp:BoundField DataField="CaseWorker" HeaderText="Case Worker" /&gt;
          &lt;asp:BoundField DataField="EventDate" HeaderText="Event Date" /&gt;
          &lt;asp:BoundField DataField="Code" HeaderText="Code" /&gt;
          &lt;asp:BoundField DataField="TotalUnits" HeaderText="Total Units" /&gt;
          &lt;asp:BoundField DataField="EventType" HeaderText="Event Type" /&gt;
          &lt;asp:BoundField DataField="UnitCost" HeaderText="Unit Cost" /&gt;
          &lt;asp:BoundField DataField="TotalCost" HeaderText="Total Cost"/&gt;
          &lt;asp:TemplateField HeaderText="ADD"&gt;
                  &lt;ItemTemplate&gt; 
                      &lt;asp:Button  ID="AddUnit" runat="server" Text=" +1 " 
                      CommandName="AddUnit" 
                      CommandArgument='&lt;%# Eval("CaseID")+ ";" + Eval("CaseworkerID")+ ";" + Eval("EventDate")+ ";" + Eval("EventTypeID")+ ";" + ("1")%&gt;'/&gt;
                  &lt;/ItemTemplate&gt; 
              &lt;/asp:TemplateField&gt; 
          &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>then it appears impossible to get those values in the onRowDatabound Handler using (e.Row.Cells[2].Text)</p>
  
  <p>i got around this problem by not setting any of the BoundFields to Visible = "False" 
  so they are visible = "true" by default. getting the values i needed in the onRowDatabound Handler in the code behind and then making them invisible afterwards . like this.</p>
  
  <pre><code>protected void Timeevents_RowDataBound(object sender, GridViewRowEventArgs e)
          {
              if (e.Row.RowType == DataControlRowType.DataRow)
              {  // just for the datarows
                  int a = (int.Parse(e.Row.Cells[2].Text));
  
                  if (a % 2 == 0)
                  {
                      e.Row.BackColor = System.Drawing.Color.Gainsboro;
                  }
                  else
                  {
                      e.Row.BackColor = System.Drawing.Color.White;
                  }
              }
              // end if so this applies to header and data rows
              e.Row.Cells[0].Visible = false;
              e.Row.Cells[1].Visible = false;
              e.Row.Cells[2].Visible = false;
  
          }
  </code></pre>
  
  <p>being a fairly green it took me a good deal of googling round many forums and debugging to figure out that the handler cant see hidden databound fields and i couldnt seem to find the answer of how to set rowcolour based on a hidden field so i though id just post this up for others to find</p>
  
  <p>If any experts know a better or alternative way perhaps they could also add some code/comments
  cheers!</p>