Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting Visibility of Button Control in GridView Header
    text
    copied!<p>I have a gridview that displays entries from a data table. I am giving users the ability to select a subset of the data in the table by having a textbox and search button in the grid view header. The search button fires the gridview row command, and changes the underlying sqlDataSource's select command, and adds the text value from the text box as a parameter.</p> <p>This works smoothly.</p> <p>Also, I have a "Show All" button in the header, that clears out the select parameters, so all entries in the table are shown. Again, this works perfectly.</p> <p>What is NOT working is controlling the visibility of the "Show All" button control. Below is the html markup for the data grid header template:</p> <pre><code>&lt;HeaderTemplate&gt; &lt;asp:Button ID="btnShowAll" runat="server" CausesValidation="False" CommandName="ShowAll" Text="Show All" /&gt; &lt;asp:Button ID="btnSearch" runat="server" CausesValidation="True" CommandName="Search" Text="Search" ValidationGroup="vldSearch" /&gt;&lt;br /&gt; &lt;asp:TextBox ID="txtSearchName" runat="server"&gt;&lt;/asp:TextBox&gt;&amp;nbsp; &lt;asp:RequiredFieldValidator ID="vldSearchName" runat="server" ErrorMessage="You have to provide an attorney name to search for." Text="*" ControlToValidate="txtSearchName" ValidationGroup="vldSearch" ForeColor="White"&gt;&lt;/asp:RequiredFieldValidator&gt; &lt;/HeaderTemplate&gt; </code></pre> <p>In the Row Command event handler, here is how I am setting the visibility of the button:</p> <pre><code>If Not Me.dgAttorneys.HeaderRow Is Nothing Then Dim btnShowAll As Button = Me.dgAttorneys.HeaderRow.FindControl("btnShowAll") btnShowAll.Visible = Me.sqlAttorneys.SelectParameters.Count &gt; 0 Trace.Write("Show all status is " &amp; btnShowAll.Visible.ToString) End If </code></pre> <p>The trace statement is showing the correct visible status - if the "show all" button is clicked, I do a SelectParameters.Clear() on the sqlAttorneys sqlDataSource.</p> <p>Is my problem due to a misunderstanding of how the "FindControl" method works - I had assumed my new btnShowAll that I define is actually a reference to the "physical" control on the aspx page, so any changes I make to my local object is reflected in the control on the page.</p> <p>If this is not the case, what is the best way to get a reference to the button control in the header row of the grid view?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload