locked
Show or Hide a web part based on a filter RRS feed

  • Question

  • All,

    I have two excel web parts Open Commit, Open Funnel that are currently hidden, that have named parts PivottableCommit, PivotTableFunnel. 

    I have a Choice filter that has the named parts PivottableCommit and PivotTableFunnel in it.

    What I want to have happen is if they select PivottableCommit then the excel web part for Open Commit will now be visible and if PivotTableFunnel is selected, Open Commit is hidden and Open Funnel is now visible.

    Can this be done?

    Thanks,
    Mindy
    Wednesday, October 7, 2009 11:36 AM

Answers

All replies

  • Mindy,

    Try to execute the code when the choice filter selected index is changed, before executing the code you have to set the PivottableCommit and PivotTableFunnel webpart ID's in code

    protected override void Render(HtmlTextWriter writer)
            {
                SPWeb web = SPControl.GetContextWeb(Context);
                try
                {               
                    if (DDL_ChoiceFilter.Value == "PivottableCommit")
    
                    {
                        Page.ClientScript.RegisterStartupScript(Page.GetType(), "hidescript", "document.getElementById('PivottableCommit webpart ID goes here.....').style.display='none';", true);
                    }
    
                    if (DDL_ChoiceFilter.Value == "PivottableFunnel")
                    {
                        Page.ClientScript.RegisterStartupScript(Page.GetType(), "hidescript", "document.getElementById('PivottableFunnel webpart ID goes here.....').style.display='none';", true);
                    }
                }
                catch (Exception ex)
                {
                    writer.Write(ex);
                }
            }


    Best Regards, G Vijai Kumar
    Wednesday, October 7, 2009 11:47 AM
  • So would I put this in a content editor web part or in the default.aspx page?
    Wednesday, October 7, 2009 12:55 PM
  • You have to create a custom webpart with the help of the code snippet
    Best Regards, G Vijai Kumar
    Wednesday, October 7, 2009 1:01 PM
  • Someone have developed a web part for this: http://spvisibilityfilter.codeplex.com/ ;

     

    And someone had provided a solution with Javascript you can put into a content editor web part: http://wyly.wordpress.com/2009/05/22/showhide-multiple-web-parts/ ;

     

    Anyway, I think both these solutions are not so strait forward. I would like to put the two excel web parts on different pages, and provide links for user to click to switch between the two pages.

    • Marked as answer by GuYuming Wednesday, October 14, 2009 2:09 AM
    Thursday, October 8, 2009 7:39 AM