Initialize/Update RadTabs Programmatically (Code Snippet)

Thread is closed for posting
1 posts, 0 answers
  1. 152760B1-0591-4D8D-ACB8-57E362E80E0F
    152760B1-0591-4D8D-ACB8-57E362E80E0F avatar
    3 posts
    Member since:
    Apr 2009

    Posted 01 Jul 2009 Link to this post

    Requirements

    RadControls version

    2009.1.622.35
    .NET version

    3.5
    Visual Studio version

    9
    programming language

    C#
    browser support

    all browsers supported by RadControls

    DESCRIPTION
    While developing a RadTabStrip with high interactivity, I found that it's a hassle to initialize/update the different states (hide, enabled, selected) of individual RadTabs.  So I created the methods to initialize/update the RadTabs programmatically.

    HOW TO USE
    1. Add a RadTabStrip to your page with the name RadTabStrip1.
    2. Define all the text of the RadTabs on the top of the Code Behind as shown.
    3. Add the 2 methods InitTabs & AddTab into the Code Behind.
    4. You may now call from anywhere of the Code Behind to initialize/update the RadTabs as you wish.
         e.g.   InitTabs(new TabState[] { TabState.Disabled, TabState.Enabled, TabState.Selected });
     
    CODE SNIPPET

    /*  
     *  TabStates' values  
     *  ===================  
     *  Hide     - do not create tab  
     *  Disabled - create tab 
     *  Enabled  - create tab & enabled  
     *  Selected - create tab, enabled & selected  
     *  
     *  example of usage  
     *  ================  
     *  1. Disabled TAB 1, Enabled TAB 2, Selected TAB 3  
     *     InitTabs(new TabState[] { TabState.Disabled, TabState.Enabled, TabState.Selected });  
     *    
     *  2. Hide TAB 1, Selected TAB 2, Enabled TAB 3  
     *     InitTabs(new TabState[] { TabState.Hide, TabState.Selected, TabState.Enabled });  
     */  
     
    //Tabs' Text Declaration  
    public const string TAB1 = "TAB 1";  
    public const string TAB2 = "TAB 2";  
    public const string TAB3 = "TAB 3";  
    public string[] tabArray = { TAB1, TAB2, TAB3 }; 
    //TabState enum 
    public enum TabState { Hide, Disabled, Enabled, Selected }; 
     
     
    public void InitTabs(TabState[] tabStates)  
    {  
        if(tabStates.Count() != tabArray.Count())   
           return;  
          
        int i = 0;  
        RadTab tab = null;  
        RadTabStrip1.Tabs.Clear();  
      
        foreach (TabState state in tabStates)  
        {  
            if (state > TabState.Hide)  
            {  
               tab = AddTab(tabArray.ElementAt(i), state > TabState.Disabled);  
               if (state == TabState.Selected)  
                   tab.Selected = true;  
            }  
            i++;  
        }  
    }  
      
      
    private RadTab AddTab(string tabName, bool enabled)  
    {  
        RadTab tab = new RadTab(tabName);  
        tab.Enabled = enabled;  
        RadTabStrip1.Tabs.Add(tab);  
        return RadTabStrip1.FindTabByText(tabName);  
    }  

Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.