title: Showing and hiding of gridview button based on the value of a cell in the same row
body: <p>I have a gridview in my ASP.NET. in my gridview columns, i want the button on each row to show or hide if the value of a cell is the same cell is empty or null. for example, i want a button to show on each row that has Signout_Time as null or empty. i have written the code below. the issue i'm having is that the codes works in an opposite way. Buttons are showed on the rows with "Signout_Time" while the button on rows without a value for "Signout_Time" visibility becomes false. it shouldn't be so. I have also tried changing my if conditions, it still didnt work</p>
  
  <pre><code>protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {
  
    switch (e.Row.RowType) {
        case DataControlRowType.DataRow:
            DataRowView myDataRowView = (DataRowView)e.Row.DataItem;
  
            if (String.IsNullOrEmpty(myDataRowView["Signout_Time"].ToString())) {
                Button status = (Button)e.Row.FindControl("out");
  
                if (status != null) {
                    status.Visible = true;
                }
            }
  
            break
       }
   }
  </code></pre>
  
  <p></p>
  
  <pre><code>                    &lt;Columns&gt;
                          &lt;asp:BoundField HeaderText="S/N" DataField="SN" /&gt;
                          &lt;asp:BoundField HeaderText="First Name" DataField="FirstName" /&gt;
                          &lt;asp:BoundField HeaderText="Address" DataField="Address" /&gt;
                          &lt;asp:BoundField HeaderText="Phone Number" DataField="PhoneNumber" /&gt;
                          &lt;asp:BoundField HeaderText="Sex" DataField="Sex" /&gt;
                          &lt;asp:BoundField HeaderText="Reason" DataField="Reason" /&gt;
                          &lt;asp:BoundField HeaderText="SignIn" DataField="SignIn_Time" /&gt;
                          &lt;asp:BoundField HeaderText="SignOut" DataField="Signout_Time" /&gt;
  
                          &lt;asp:TemplateField HeaderText="Action" Visible="True"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:Button ID="out" runat="server" Text="Sign out" CommandName="SignOut"  CommandArgument='&lt;%#Eval("SN") %&gt;'/&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
                      &lt;/Columns&gt;
  
              &lt;PagerSettings FirstPageText="First" LastPageText="Last" Mode="NumericFirstLast" PageButtonCount="5" /&gt;
  
  
          &lt;/asp:GridView&gt;
  </code></pre>