Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I hide a datagrid when the page loads?

Posted on 2014-01-15
3
Medium Priority
?
396 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 750 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

721 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