Webpart ASP.Net

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



    Web Parts Demo


    
    

        
       
            
            
                
                
                
            
            
                
                
                
            
        

                    
                        
                                                        ID="Label1">Penguin Classics releases new translation of "In Search of Lost Time"
                        

                    
                

                    
                    
                

                    
                        
                            
                                A
                                B
                                C
                                D
                                E
                                F
                            
                        

                    
                

                  
                     
                        
                           
                              
                              
                           

                        
                     

                  
                

                    
                    
                

                   
                      
                         
                         
                      

                      
                      
                      
                      
                      
                      
                      
                      
                      
                      
                      
                      
                   
                

    

    


File: Control.ascx
<%@ Control Language="C#" AutoEventWireup="true" 
CodeFile="Control.ascx.cs" 
Inherits="DisplayModeMenu" %>   
  

      Borderwidth="1" 
    Width="230" 
    BackColor="lightgray"
    Font-Names="Verdana, Arial, Sans Serif" >
          Text=" Display Mode" 
      Font-Bold="true"
      Font-Size="8"
      Width="120" />
          AutoPostBack="true" 
      EnableViewState="false" 
      Width="120"
      OnSelectedIndexChanged="ddlDisplayMode_SelectedIndexChanged" />
  

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_Init( object sender, EventArgs e )
   {
      Page.InitComplete += new EventHandler( InitComplete );
   }
   public void InitComplete( object sender, System.EventArgs e )
   {
      webPartManager = WebPartManager.GetCurrentWebPartManager( Page );
      String browseModeName = WebPartManager.BrowseDisplayMode.Name;
      foreach ( WebPartDisplayMode mode in
        webPartManager.SupportedDisplayModes )
      {
         String modeName = mode.Name;
         if ( mode.IsEnabled( webPartManager ) )
         {
            ListItem listItem = new ListItem( modeName, modeName );
            ddlDisplayMode.Items.Add( listItem );
         }
      }
   }
   public void ddlDisplayMode_SelectedIndexChanged( object sender,EventArgs e )
   {
      String selectedMode = ddlDisplayMode.SelectedValue;
      WebPartDisplayMode mode =
       webPartManager.SupportedDisplayModes[selectedMode];
      if ( mode != null )
      {
         webPartManager.DisplayMode = mode;
      }
   }
   public void Page_PreRender( object sender, EventArgs e )
   {
      ListItemCollection items = ddlDisplayMode.Items;
      int selectedIndex =
        items.IndexOf( items.FindByText( webPartManager.DisplayMode.Name ) );
      ddlDisplayMode.SelectedIndex = selectedIndex;
   }
}