title: Gridview, hide button on RowDataBound?
body: <p>Very quick question - I must not be seeing it properly, but is there any reason why the ASP button "btnEdit" is still visible in the gridview? On RowDatabound (for testing) I'm just trying to hide it with the plan to put an if statement around it later.</p>
  
  <p><strong>Code behind (RowDataBound)</strong></p>
  
  <pre><code>    protected void gvEditUser_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
          Button btnEdit = (Button)e.Row.FindControl("btnEdit");
          btnEdit.Visible = false;
          if (e.Row.RowState != null)
          {
              if ((e.Row.RowState &amp; DataControlRowState.Edit) &gt; 0)
              {
  
                  CheckBox cbAdmin = (CheckBox)e.Row.FindControl("cbAdmin");
                  DataRowView dr = e.Row.DataItem as DataRowView;
                  if (Convert.ToBoolean(dr["admin"] = true))
                  {
                      cbAdmin.Checked = true;
                  }
                  else
                  {
                      cbAdmin.Checked = false;
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>ASPX Page (GridView)</strong></p>
  
  <pre><code>        &lt;asp:GridView ID="gvEditUser" runat="server" AllowPaging="True" AutoGenerateColumns="False" OnRowCancelingEdit="gvEditUser_RowCancelingEdit" OnRowEditing="gvEditUser_RowEditing" OnRowCommand="gvEditUser_RowCommand" OnRowDeleting="gvEditUser_RowDeleting" OnPageIndexChanging="gvEditUser_PageIndexChanging" CellPadding="4" GridLines="None" CssClass="size12_text" PageSize="10"&gt;
          &lt;Columns&gt;
              &lt;asp:TemplateField HeaderText="Username"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="lbUsername" runat="server" Text='&lt;%# Eval("username") %&gt;' &gt;&lt;/asp:Label&gt;
                      &lt;asp:Label ID="lbUserID" runat="server" Text='&lt;%# Eval("userid") %&gt;' Visible="false"&gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="Full Name"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="lbFullName" runat="server" Text='&lt;%# Eval("fullname") %&gt;' &gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="Email"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;a href="mailto:&lt;%# Eval("email") %&gt;"&gt;Email&lt;/a&gt;
                      &lt;asp:Label ID="lbEmail" runat="server" Visible="false" Text='&lt;%# Eval("email") %&gt;' &gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="Address"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="lbAddress" runat="server" Text='&lt;%# Eval("housenumber")!=DBNull.Value ? Eval("housetype").ToString() == "0" ? Eval("HouseNumber").ToString() + " " + Eval("Address01").ToString() + " " + Eval("Address02").ToString() + " " + Eval("StreetType").ToString() + "&lt;br /&gt;" + Eval("Suburb").ToString() + ", " + Eval("State").ToString() + " " + Eval("Postcode").ToString() + "&lt;br /&gt;" + Eval("Country").ToString() : Eval("Address01").ToString() + " " + Eval("HouseNumber").ToString() + " " + Eval("Address02").ToString() + " " + Eval("StreetType").ToString() + "&lt;br /&gt;" + Eval("Suburb").ToString() + ", " + Eval("State").ToString() + " " + Eval("Postcode").ToString() + "&lt;br /&gt;" + Eval("Country").ToString() : "&lt;div class=\"size11_text\"&gt;No Address in system.&lt;/div&gt;"%&gt;'&gt;&lt;/asp:Label&gt;
                      &lt;asp:Label ID="lbAddressRaw" runat="server" Text='&lt;%# Eval("housenumber")!=DBNull.Value ? Eval("housetype").ToString() == "0" ? Eval("HouseNumber").ToString() + " " + Eval("Address01").ToString() + " " + (Eval("Address02")!=DBNull.Value ? Eval("Address02").ToString() + " " : "") + Eval("StreetType").ToString() : Eval("Address01").ToString() + " " + Eval("HouseNumber").ToString() + " " + Eval("Address02").ToString() + " " + Eval("StreetType").ToString() : ""%&gt;' Visible="false"&gt;&lt;/asp:Label&gt;
                      &lt;asp:Label ID="lbHouseType" runat="server" Text='&lt;%# Eval("housetype") %&gt;' Visible="false"&gt;&lt;/asp:Label&gt;
                      &lt;asp:Label ID="lbHouseNumber" runat="server" Text='&lt;%# Eval("housenumber") %&gt;' Visible="false"&gt;&lt;/asp:Label&gt;
                      &lt;asp:Label ID="lbAddress01" runat="server" Text='&lt;%# Eval("address01") %&gt;' Visible="false"&gt;&lt;/asp:Label&gt;
                      &lt;asp:Label ID="lbAddress02" runat="server" Text='&lt;%# Eval("address02") %&gt;' Visible="false"&gt;&lt;/asp:Label&gt;
                      &lt;asp:Label ID="lbStreetType" runat="server" Text='&lt;%# Eval("streettype") %&gt;' Visible="false"&gt;&lt;/asp:Label&gt;
                      &lt;asp:Label ID="lbSuburb" runat="server" Text='&lt;%# Eval("suburb") %&gt;' Visible="false"&gt;&lt;/asp:Label&gt;
                      &lt;asp:Label ID="lbState" runat="server" Text='&lt;%# Eval("state") %&gt;' Visible="false"&gt;&lt;/asp:Label&gt;
                      &lt;asp:Label ID="lbPostcode" runat="server" Text='&lt;%# Eval("postcode") %&gt;' Visible="false"&gt;&lt;/asp:Label&gt;
                      &lt;asp:Label ID="lbCountry" runat="server" Text='&lt;%# Eval("country") %&gt;' Visible="false"&gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="Home Phone"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="lbTelephone" runat="server" Text='&lt;%# Eval("telephone") %&gt;' &gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="Work Phone"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="lbWorkPhone" runat="server" Text='&lt;%# Eval("workphone") %&gt;' &gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="Mobile"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="lbMobile" runat="server" Text='&lt;%# Eval("mobile") %&gt;' &gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="Shirt Size"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="lbShirtSize" runat="server" Text='&lt;%# Eval("shirtsize") %&gt;' &gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="Pant Size"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="lbPantSize" runat="server" Text='&lt;%# Eval("pantsize") %&gt;' &gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="Admin"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:CheckBox ID="cbAdmin" runat="server" Checked='&lt;%# Convert.ToBoolean(Eval("admin")) %&gt;' Enabled="false" /&gt;
                      &lt;asp:Label ID="lbAdmin" runat="server" Text='&lt;%# Eval("admin") %&gt;' Visible="false" &gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="Last Login"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="lbLastLogin" runat="server" Text='&lt;%# Eval("lastlogin") %&gt;' CssClass="size11_text_blurb"&gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderStyle-Width="100px"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Button ID="btnPasswordReset" runat="server" CssClass="txtbuttonsmall" CommandName="ResetPassword" Text="Reset Password" OnClientClick='&lt;%# Eval("username","return confirm(\"Reset password for {0}?\");") %&gt;'&gt;&lt;/asp:Button&gt;&lt;br /&gt;
                      &lt;asp:Button ID="btnEdit" runat="server" CssClass="txtbuttonsmall" CommandName="Edit" Text="Edit User"&gt;&lt;/asp:Button&gt;&lt;br /&gt;
                      &lt;asp:Button ID="btnDelete" runat="server" CssClass="txtbuttonsmall" CommandName="Delete" Text="Delete User" OnClientClick='&lt;%# Eval("username","return confirm(\"Delete user {0}?\");") %&gt;'&gt;&lt;/asp:Button&gt;
                  &lt;/ItemTemplate&gt;
                  &lt;EditItemTemplate&gt;
                      &lt;asp:Button ID="btnCancel" runat="server" CommandName="Cancel" Text="Cancel Edit" CssClass="txtbutton"&gt;&lt;/asp:Button&gt;
                  &lt;/EditItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
          &lt;/Columns&gt;
          &lt;AlternatingRowStyle BackColor="#d8e6f0" /&gt;
          &lt;EditRowStyle BackColor="#a3cbe8" /&gt;
          &lt;HeaderStyle BackColor="#032035" ForeColor="White" CssClass="size12_text" /&gt;
          &lt;PagerStyle BackColor="#032035" ForeColor="White" HorizontalAlign="Center" CssClass="size12_text" /&gt;
          &lt;RowStyle BackColor="#f9fbfc" /&gt;
      &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>Cheers,</p>
  
  <p>Trent</p>