Solved

How do I hide a datagrid when the page loads?

Posted on 2014-01-15
3
392 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VIDEO DATASOURCE Control Resize issue 2 30
JSON Deserialize issue 6 26
SSIS Start 2 20
ASP.NET MVC - Views 3 17
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…

809 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