Link to home
Start Free TrialLog in
Avatar of programmher
programmher

asked on

How do I hide a datagrid when the page loads?

I have a page that has two data grids.  One displays authors and when the author is selected all of the books written by that author are displayed on the same page.  The user can then select all or some of the books and submit a request for those selected books to be pulled by the librarian.

My question is how do I get the second grid to be hidden when the page loads?  The client want to be able to collapse and expand/hide or show the second grid.

My code for the grids
     <div>
        <asp:GridView runat="server" ID="gvBooks" DataSourceID="Books_ds" />
        <asp:GridView runat="server" ID="gAuthorss" DataSourceID="Authors_ds" AutoGenerateSelectButton="true" DataKeyNames="AuthorName" />     
    </div>

Open in new window


My code  behind
    public static List<AuthorSelection> GetAuthorList()
    {
        List<AuthorSelection> Authors = new List<AuthorSelection>();
        SearchResultCollection src = ds.FindAll();

        foreach (SearchResult sr in src)
        {
            if (!sr.Properties.Contains("msexchhidefromaddresslists") || (sr.Properties["msexchhidefromaddresslists"][0].ToString() != "True"))
            {
                AuthorSelection auths = new AuthorSelection();
                if (sr.Properties.Contains("authorname")) gs._name = sr.Properties["authorname"][0].ToString();
                if (sr.Properties.Contains("displayedauthname")) gs._display = sr.Properties["displayedauthname"][0].ToString();
        Authors.Add(gs);
            }

        }
        return Authors;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of programmher
programmher

ASKER

Thanks - that is what I was trying but was unsucessful.  I will search some more for the actual code.  I am likely missing something simpe.
You could use a ViewState variable or a CheckBox.

In the Page_Load, it would be something like this:

protected void Page_Load(object sender, EventArgs e)
{
     gvAuthors.Visible = (ShowHideSecondGrid.Checked);
}