ComponentOne ToolBar for ASP.NET AJAX: ToolBar for ASP.NET AJAX Task-Based Help > Adding Child ToolBar Items

Adding Child ToolBar Items

Child toolbar items can be added to C1ToolBarDropDownList and C1ToolBarSplitButton items at design time using the designer, declaratively in the.aspx/ascx file, programmatically using the server-side API, or dynamically using the client-side object model. Click on either of the following links to expand the steps for the designer, HTML Markup, or code.

To add child toolbar items to C1ToolBarDropDownList and C1ToolBarSplitButton using the designer

1.   Create an AJAX enabled website.

2.   Add C1ToolBar to your page.

3.   Right-click on the control and select Edit ToolBar.

The C1ToolBar Designer Form appears. For conceptual information about the elements in the C1ToolBar Designer Form see, C1ToolBar Designer Form.

4.   Right-click on C1TooBar1 and select Add Child | ToolBarButton to add a C1ToolBarButton item to the ToolBar control.

5.   Right-click on C1ToolBar1 and select Add Child | ToolBarDropDownList to add a C1ToolBarDropDownList item to the ToolBar control.

6.   Right-click on ToolBarDropDownList1 and select Add Child | ToolBarButton to add a C1ToolBarButton to ToolBarDropDownList1. Repeat this once more to add a total of two buttons to ToolBarDropDownList1 item.

7.   Right-click on C1ToolBar1 and Add Child | ToolBarSplitButton to add a C1ToolBarSplitButton item to the ToolBar control.

8.   Right-click on ToolBarSplitButton1 and select Add Child | ToolBarButton to add a C1ToolBarButton to ToolBarSplitButton1. Repeat this once more to add a total of two buttons to ToolBarSplitButton1 item.

9.   Run your project.

To add child toolbar items to C1ToolBarDropDownList and C1ToolBarSplitButton declaratively

Select the source tab to switch to source view and add the following HTML Markup within the <body> tags.

<form id="form1" runat="server">

<cc2:C1ToolBar ID="C1ToolBar1" runat="server" Dock="None"

            VisualStylePath="~/C1WebControls/VisualStyles">

            <Items>

                <cc2:C1ToolBarButton runat="server" Index="0" IsTemplated="False"

                    Text="ToolBarButton1">

                </cc2:C1ToolBarButton>

                <cc2:C1ToolBarDropDownList runat="server" Index="1" IsTemplated="False"

                    Text="ToolBarDropDownList1">

                    <Items>

                        <cc2:C1ToolBarButton runat="server" Index="0" IsTemplated="False"

                            Text="ToolBarButton1">

                        </cc2:C1ToolBarButton>

                        <cc2:C1ToolBarButton runat="server" Index="1" IsTemplated="False"

                            Text="ToolBarButton2">

                        </cc2:C1ToolBarButton>

                    </Items>

                </cc2:C1ToolBarDropDownList>

                <cc2:C1ToolBarSplitButton runat="server" EnabledDefaultButton="False" Index="2"

                    IsTemplated="False" NestedItemIndex="0" Text="ToolBarSplitButton1">

                    <Items>

                        <cc2:C1ToolBarButton runat="server" Index="0" IsTemplated="False"

                            Text="ToolBarButton1">

                        </cc2:C1ToolBarButton>

                        <cc2:C1ToolBarButton runat="server" Index="1" IsTemplated="False"

                            Text="ToolBarButton2">

                        </cc2:C1ToolBarButton>

                    </Items>

                </cc2:C1ToolBarSplitButton>

            </Items>

        </cc2:C1ToolBar> </form>

To add child toolbar items to C1ToolBarDropDownList programmatically

To add C1ToolBarDropDownList and three child ToolBarButtons to C1ToolBar programmatically in the code behind, complete the following:

1.   Add C1ToolBar to your page.

2.   Declare the C1.Web.UI.Controls.C1ToolBar namespace at the top of your code behind file:

      Visual Basic

Imports C1.Web.UI.Controls.C1ToolBar

      C#

Using C1.Web.UI.Controls.C1ToolBar;

3.   Enter the following code in the Page_Load event handler:

      Visual Basic

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    If Not Page.IsPostBack Then

        Dim tb As New C1ToolBar()

        PlaceHolder1.Controls.Add(tb)

       

        'create a new toolbarbutton

        Dim button As New C1ToolBarButton()

        button.Text = "ToolBarButton1"

        'add the button to the C1ToolBar control

        tb.Items.Add(button)

       

        'create a new toolbardropdownlist

        Dim dropDownlist As New C1ToolBarDropDownList()

        dropDownlist.Text = "ToolBarDropDownlist1"

        'add the C1ToolBarDropDownList to the C1ToolBar control

        tb.Items.Add(dropDownlist)

       

        'create a new button2

        Dim button2 As New C1ToolBarButton()

        'add button2 to the C1ToolBarDropDownList

        dropDownlist.Items.Add(button2)

        button2.Text = "Button2"

        

        'create a new button3

        Dim button3 As New C1ToolBarButton()

        button3.Text = "Button3"

        'add button3 to the C1ToolBarDropDownList

        dropDownlist.Items.Add(button3)

       

        'create a new C1ToolBarSplitButton

        Dim splitButton As New C1ToolBarSplitButton()

        'create a new button4

        Dim button4 As New C1ToolBarButton()

        'add button4 to the splitbutton

        splitButton.Items.Add(button4)

        splitButton.Text = "ToolBarSplitButton1"

        button4.Text = "Button4"

       

        'create a new button5

        Dim button5 As New C1ToolBarButton()

        'add button5 to the splitbutton

        splitButton.Items.Add(button5)

        button5.Text = "Button5"

        'add the C1ToolBarSplitButton to the C1ToolBar control

         tb.Items.Add(splitButton)

       

    End If

End Sub                    

      C#

  protected void Page_Load(object sender, EventArgs e)

    {

        if (!Page.IsPostBack)

        {

            C1ToolBar tb = new C1ToolBar();

            PlaceHolder1.Controls.Add(tb);

           

            //create a new toolbarbutton

            C1ToolBarButton button = new C1ToolBarButton();

            button.Text = "ToolBarButton1";

            //add the button to the C1ToolBar control

            tb.Items.Add(button);

           

            //create a new toolbardropdownlist

            C1ToolBarDropDownList dropDownlist = new C1ToolBarDropDownList();

            dropDownlist.Text = "ToolBarDropDownlist1";

            //add the C1ToolBarDropDownList to the C1ToolBar control      

            tb.Items.Add(dropDownlist);

           

            //create a new button2

            C1ToolBarButton button2 = new C1ToolBarButton();

            //add button2 to the C1ToolBarDropDownList

            dropDownlist.Items.Add(button2);

            button2.Text = "Button2";

           

            //create a new button3

            C1ToolBarButton button3 = new C1ToolBarButton();

            button3.Text = "Button3";

            //add button3 to the C1ToolBarDropDownList

            dropDownlist.Items.Add(button3);

          

            //create a new C1ToolBarSplitButton

            C1ToolBarSplitButton splitButton = new C1ToolBarSplitButton();

            //create a new button4

            C1ToolBarButton button4= new C1ToolBarButton();

            //add button4 to the splitbutton

            splitButton.Items.Add(button4);

            splitButton.Text = "ToolBarSplitButton1";

            button4.Text = "Button4";

           

            //create a new button5

            C1ToolBarButton button5 = new C1ToolBarButton();

            //add button5 to the splitbutton

            splitButton.Items.Add(button5);

            button5.Text = "Button5";

            //add the C1ToolBarSplitButton to the C1ToolBar control

            tb.Items.Add(splitButton);

 

        }

    }                             

4.   Run you project and notice the new toolbar items and child toolbar items:

 


Send comments about this topic to ComponentOne.
Copyright © 1987-2010 ComponentOne LLC. All rights reserved.