Display Mode Menu : WebPartManager « WebPart « ASP.Net

ASP.Net
1. ADO.net Database
2. Ajax
3. Asp Control
4. Collections
5. Components
6. Data Binding
7. Development
8. File Directory
9. HTML Control
10. Language Basics
11. Login Security
12. Mobile Control
13. Network
14. Page
15. Request
16. Response
17. Server
18. Session Cookie
19. Sitemap
20. Theme Style
21. User Control and Master Page
22. Validation by Control
23. Validation by Function
24. WebPart
25. WPF
26. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.Net » WebPart » WebPartManager 
Display Mode Menu


<%@ Page Language="C#" %>
<%@ Register Src="Control.ascx" TagName="DisplayModeMenul" TagPrefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Web Parts Demo</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:WebPartManager ID="WebPartManager1" runat="server" />
       <uc1:DisplayModeMenul ID="DisplayModeMenul1" runat="server" />
            <table>
            <tr>
                <td>
                    <asp:WebPartZone ID="WebPartZone1" Runat="server" Width="215px" Height="191px" HeaderText="News">
                        <ZoneTemplate>
                            <asp:Label Runat="server" Title="Today's News" 
                            ID="Label1"><br />Penguin Classics releases new translation of "In Search of Lost Time"</asp:Label>
                        </ZoneTemplate>
                    </asp:WebPartZone>
                </td>
                <td>
                    <asp:WebPartZone ID="WebPartZone2" Runat="server" Width="98px" Height="181px">
                    </asp:WebPartZone>
                </td>
                <td>
                    <asp:WebPartZone ID="WebPartZone3" Runat="server" Width="207px" Height="173px" HeaderText="Sponsors">
                        <ZoneTemplate>
                            <asp:ListBox Runat="server" ID="ListBox1">
                                <asp:ListItem>A</asp:ListItem>
                                <asp:ListItem>B</asp:ListItem>
                                <asp:ListItem>C</asp:ListItem>
                                <asp:ListItem>D</asp:ListItem>
                                <asp:ListItem>E</asp:ListItem>
                                <asp:ListItem>F</asp:ListItem>
                            </asp:ListBox>
                        </ZoneTemplate>
                    </asp:WebPartZone>
                </td>
            </tr>
            <tr>
                <td>
                  <asp:CatalogZone ID="CatalogZone1" runat="server">
                     <ZoneTemplate>
                        <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" runat="server">
                           <WebPartsTemplate>
                              <asp:Calendar ID="Calendar1" runat="server" title="Calendar" />
                              <asp:FileUpload ID="FileUpload1" runat="server" title="Upload Files" />
                           </WebPartsTemplate>
                        </asp:DeclarativeCatalogPart>
                     </ZoneTemplate>
                  </asp:CatalogZone>
                </td>
                <td>
                    <asp:WebPartZone ID="WebPartZone5" Runat="server" Width="98px" Height="161px">
                    </asp:WebPartZone>
                </td>
                <td>
                   <asp:EditorZone ID="EditorZone1" runat="server" BackColor="#F7F6F3" BorderColor="Navy" BorderWidth="1px" Font-Names="Verdana" Padding="6" >
                      <ZoneTemplate>
                         <asp:AppearanceEditorPart ID="AppearanceEditorPart1" runat="server" />
                         <asp:LayoutEditorPart ID="LayoutEditorPart1" runat="server" />
                      </ZoneTemplate>
                      <LabelStyle Font-Size="0.8em" ForeColor="Red" />
                      <HeaderStyle BackColor="#E2DED6" Font-Bold="True" Font-Size="0.8em" ForeColor="Red" />
                      <HeaderVerbStyle Font-Bold="False" Font-Size="0.8em" Font-Underline="False" ForeColor="Red" />
                      <PartChromeStyle BorderColor="#E2DED6" BorderStyle="Solid" BorderWidth="1px" />
                      <PartStyle BorderColor="#F7F6F3" BorderWidth="5px" />
                      <FooterStyle BackColor="#E2DED6" HorizontalAlign="Right" />
                      <EditUIStyle Font-Names="Verdana" Font-Size="0.8em" ForeColor="Red" />
                      <InstructionTextStyle Font-Size="0.8em" ForeColor="Red" />
                      <ErrorStyle Font-Size="0.8em" />
                      <VerbStyle Font-Names="Verdana" Font-Size="0.8em" ForeColor="Red" />
                      <EmptyZoneTextStyle Font-Size="0.8em" ForeColor="Red" />
                      <PartTitleStyle Font-Bold="True" Font-Size="0.8em" ForeColor="Red" />
                   </asp:EditorZone>
                </td>
            </tr>
        </table>

    </div>
    </form>
</body>
</html>


File: Control.ascx

<%@ Control Language="C#" AutoEventWireup="true" 
CodeFile="Control.ascx.cs" 
Inherits="DisplayModeMenu" %>   
  
<div>
  <asp:Panel ID="Panel1" runat="server" 
    Borderwidth="1" 
    Width="230" 
    BackColor="lightgray"
    Font-Names="Verdana, Arial, Sans Serif" >
    <asp:Label ID="Label1" runat="server" 
      Text="&nbsp;Display Mode" 
      Font-Bold="true"
      Font-Size="8"
      Width="120" />
    <asp:DropDownList ID="ddlDisplayMode" runat="server"  
      AutoPostBack="true" 
      EnableViewState="false" 
      Width="120"
      OnSelectedIndexChanged="ddlDisplayMode_SelectedIndexChanged" />
  </asp:Panel>
</div>

File: Control.ascx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class DisplayModeMenu : System.Web.UI.UserControl
{
   WebPartManager webPartManager;

   public void Page_Initobject sender, EventArgs e )
   {
      Page.InitComplete += new EventHandlerInitComplete );
   }
   public void InitCompleteobject sender, System.EventArgs e )
   {
      webPartManager = WebPartManager.GetCurrentWebPartManagerPage );

      String browseModeName = WebPartManager.BrowseDisplayMode.Name;

      foreach WebPartDisplayMode mode in
        webPartManager.SupportedDisplayModes )
      {
         String modeName = mode.Name;
         if mode.IsEnabledwebPartManager ) )
         {
            ListItem listItem = new ListItemmodeName, modeName );
            ddlDisplayMode.Items.AddlistItem );
         }
      }
   }

   public void ddlDisplayMode_SelectedIndexChangedobject sender,EventArgs e )
   {
      String selectedMode = ddlDisplayMode.SelectedValue;

      WebPartDisplayMode mode =
       webPartManager.SupportedDisplayModes[selectedMode];
      if mode != null )
      {
         webPartManager.DisplayMode = mode;
      }
   }

   public void Page_PreRenderobject sender, EventArgs e )
   {
      ListItemCollection items = ddlDisplayMode.Items;
      int selectedIndex =
        items.IndexOfitems.FindByTextwebPartManager.DisplayMode.Name ) );
      ddlDisplayMode.SelectedIndex = selectedIndex;
   }
}

 
Related examples in the same category
1. Web part with WebPartManager
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.