Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3424434
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:28:25+00:00 2026-05-18T06:28:25+00:00

I have a gridview that displays entries from a data table. I am giving

  • 0

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.

This works smoothly.

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.

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:

<HeaderTemplate>
    <asp:Button ID="btnShowAll" runat="server" CausesValidation="False" CommandName="ShowAll" Text="Show All" />
    <asp:Button ID="btnSearch" runat="server" CausesValidation="True" CommandName="Search" Text="Search" ValidationGroup="vldSearch" /><br />
    <asp:TextBox ID="txtSearchName" runat="server"></asp:TextBox>&nbsp;
    <asp:RequiredFieldValidator ID="vldSearchName" runat="server" ErrorMessage="You have to provide an attorney name to search for." Text="*" ControlToValidate="txtSearchName" ValidationGroup="vldSearch" ForeColor="White"></asp:RequiredFieldValidator>
</HeaderTemplate>

In the Row Command event handler, here is how I am setting the visibility of the button:

If Not Me.dgAttorneys.HeaderRow Is Nothing Then
    Dim btnShowAll As Button = Me.dgAttorneys.HeaderRow.FindControl("btnShowAll")
    btnShowAll.Visible = Me.sqlAttorneys.SelectParameters.Count > 0
    Trace.Write("Show all status is " & btnShowAll.Visible.ToString)
End If

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.

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.

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T06:28:26+00:00Added an answer on May 18, 2026 at 6:28 am

    I managed to get the button behavior to work – it was all to do with where in the overall process I was setting the button visibility. I moved that code block (setting the button visibility based on the presence of a search parameter) to the DataBound event for the data grid, and the button’s visibility was set as it should be.

    I suspect this is because during the overall data binding process, based on the state of the overall grid view and each grid row, the appropriate template object is used to render each row. Thus, any changes made to the button’s visible property were being overridden during the data binding process. By shifting my code to set the visibility until after the data binding was complete, then it took effect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a gridview that displays data from a database. The datbase stores the
I have a GridView that is bound to a select statement from a table.
I have a gridview that displays data that I retrieved from a database along
In my Webforms 3.5 application, I have a GridView of users that displays the
I have a Gridview that displays paged results from a search query. The problem
I have a gridview that displays the contents of a database table, using an
I have a ASP.NET/VB that had a GridView to display a list of users
I have a gridview that displays items details, I added two template fields one
I have a Gridview that displays a huge list of products. On Client click
I have a gridview that displays all trips - within that gridview I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.