Solved

How do I hide a datagrid when the page loads?

Posted on 2014-01-15
3
387 Views
Last Modified: 2014-01-16
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

0
Comment
Question by:programmher
  • 2
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 39785288
I would think that you need some way to store the state of the show/hide for the second grid.  In the Page_Load event handler, you could then set the GridView.Visible property to the current state for the show/hide.
0
 

Author Comment

by:programmher
ID: 39785309
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.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39785359
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);
}
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now