title: ASPxGridView: Cannot hide custom command button selectively. Is it a bug on my side?
body: <p><strong>Summary:</strong> When trying to hide a custom command button in <code>ASPxGridView</code> command column, it hides the buttons strangely, one of the buton texts appears in the filter row entry, and the button handlers stop working. The error message like <em>"More controls with the DXCBtn_0_9_-1 were found. The FindControl requires unique identifiers of the controls"</em> (loosely translated) appeares.</p>
  
  <p>I am using DevExpress 14.2.3.0, the grid view is nested in another grid views and in ASPxRoundPanels.</p>
  
  <p><strong>Details:</strong> The command column contains the following custom buttons...</p>
  
  <pre><code>    &lt;dx:GridViewCommandColumn VisibleIndex="9"&gt;
          &lt;CustomButtons&gt;
              &lt;dx:GridViewCommandColumnCustomButton ID="btnClose" Text="Close as done"&gt;
              &lt;/dx:GridViewCommandColumnCustomButton&gt;
              &lt;dx:GridViewCommandColumnCustomButton ID="btnReopen" Text="Reopen"&gt;
              &lt;/dx:GridViewCommandColumnCustomButton&gt;
          &lt;/CustomButtons&gt;
      &lt;/dx:GridViewCommandColumn&gt;
  </code></pre>
  
  <p>The buttons are displayed fine (as links) and the following code handles them nicely:</p>
  
  <pre><code>protected void gvMilestoneTasks_CustomButtonCallback(object sender, ASPxGridViewCustomButtonCallbackEventArgs e)
  {
      ASPxGridView grid = sender as ASPxGridView;
      if (e.ButtonID == "btnClose")
      {
          int milestoneID = Convert.ToInt32(grid.GetRowValues(e.VisibleIndex, "ID"));
          DbUtil.ExecuteNonQuery(String.Format("EXEC sp_milestone_tasks_close_open {0}, 0, N'{1}'", 
                                          milestoneID, Page.User.Identity.Name));
          grid.DataBind();
      } else if (e.ButtonID == "btnReopen")
      {
          int milestoneID = Convert.ToInt32(grid.GetRowValues(e.VisibleIndex, "ID"));
          DbUtil.ExecuteNonQuery(String.Format("EXEC sp_milestone_tasks_close_open {0}, 1, N'{1}'",
                                          milestoneID, Page.User.Identity.Name));
          grid.DataBind();
      }
  }
  </code></pre>
  
  <p>(That is, dedicated SQL stored procedures with different arguments are called [notice the second argument if curious], and the <code>grid.DataBind();</code> is used to refresh the content of the status column.)</p>
  
  <p>I want to show only one of the buttons. When the row shows the open one, only the Close button should be displayed and active. When the row shows it was closed earlier, only the Reopen button should be visible and active.</p>
  
  <p>I tried to handle visibility in the <code>CustomButtonInitialize</code> event handler (based on the status info -- when the <code>closed</code> is NULL in the database, then it is open; otherwise, the <code>closed</code> contains the datetime of when it was closed):</p>
  
  <pre><code>protected void gvMilestoneTasks_CustomButtonInitialize(object sender, ASPxGridViewCustomButtonEventArgs e)
  {
      if (e.VisibleIndex == -1)
          return;
  
      ASPxGridView grid = sender as ASPxGridView;
      if (e.ButtonID == "btnClose")
      {
          object o = grid.GetRowValues(e.VisibleIndex, "closed");
          bool flagVisible = Convert.IsDBNull(o);
          e.Visible = flagVisible ? DefaultBoolean.True : DefaultBoolean.False;
      }
      else if (e.ButtonID == "btnReopen")
      {
          object o = grid.GetRowValues(e.VisibleIndex, "closed");
          bool flagVisible = !Convert.IsDBNull(o);
          e.Visible = flagVisible ? DefaultBoolean.True : DefaultBoolean.False;
      }
  }
  </code></pre>
  
  <p>I can observe also an error message in the browser in the sense <em>"More controls with the DXCBtn_0_9_-1 were found. The FindControl requires unique identifiers of the controls"</em> (loosely translated) -- this is hidden somewhere deep in the controls; I am not using the <code>FindControl</code>.</p>
  
  <p>Where is the bug hidden?</p>
  
  <p>Thanks for your help.</p>