|
| 1 | +--- |
| 2 | +title: ButtonGroup |
| 3 | +page_title: ButtonGroup | Telerik UI for ASP.NET Core HtmlHelpers |
| 4 | +description: "Learn the basics when working with the ButtonGroup HtmlHelper for ASP.NET Core (MVC 6 or ASP.NET Core MVC)." |
| 5 | +slug: htmlhelpers_buttongroup_aspnetcore |
| 6 | +--- |
| 7 | + |
| 8 | +# ButtonGroup HtmlHelper Overview |
| 9 | + |
| 10 | +The ButtonGroup HtmlHelper extension is a server-side wrapper for the [Kendo UI ButtonGroup](https://demos.telerik.com/kendo-ui/buttongroup/index) widget. |
| 11 | + |
| 12 | +For more information on the HtmlHelper, refer to the article on the [ButtonGroup HtmlHelper for ASP.NET MVC](http://docs.telerik.com/aspnet-mvc/helpers/buttongroup/overview). |
| 13 | + |
| 14 | +## Getting Started |
| 15 | + |
| 16 | +### Initialization |
| 17 | + |
| 18 | +The following example demonstrates how to initialize the ButtonGroup. |
| 19 | + |
| 20 | +###### Example |
| 21 | + |
| 22 | +``` |
| 23 | + @(Html.Kendo().ButtonGroup() |
| 24 | + .Name("select-period") |
| 25 | + .Items(t => |
| 26 | + { |
| 27 | + t.Add().Text("Month"); |
| 28 | + t.Add().Text("Quarter"); |
| 29 | + t.Add().Text("Year"); |
| 30 | + })) |
| 31 | +``` |
| 32 | + |
| 33 | +## Icons |
| 34 | + |
| 35 | +Kendo UI ButtonGroup provides a method for configuring icons - `.Icon()`. |
| 36 | + |
| 37 | +###### Example |
| 38 | + |
| 39 | +``` |
| 40 | + @(Html.Kendo().ButtonGroup() |
| 41 | + .Name("player") |
| 42 | + .Items(t => |
| 43 | + { |
| 44 | + t.Add().Icon("play"); |
| 45 | + t.Add().Icon("pause"); |
| 46 | + t.Add().Icon("stop"); |
| 47 | + })) |
| 48 | +``` |
| 49 | + |
| 50 | +The above configuration is expected to produce the HTML output from the following example. |
| 51 | + |
| 52 | +###### Example |
| 53 | + |
| 54 | + <div class="k-button-group k-widget" data-role="buttongroup" id="player" role="group" tabindex="0"> |
| 55 | + <span data-icon="play" aria-pressed="false" role="button" class="k-button k-button-icon"> |
| 56 | + <span class="k-icon k-i-play"></span> |
| 57 | + </span> |
| 58 | + <span data-icon="pause" aria-pressed="false" role="button" class="k-button k-button-icon"> |
| 59 | + <span class="k-icon k-i-pause"></span> |
| 60 | + </span> |
| 61 | + <span data-icon="stop" aria-pressed="false" role="button" class="k-button k-button-icon"> |
| 62 | + <span class="k-icon k-i-stop"></span> |
| 63 | + </span> |
| 64 | + </div> |
| 65 | + |
| 66 | +## Features |
| 67 | + |
| 68 | +### Enable and Disable ButtonGroup |
| 69 | + |
| 70 | +Kendo UI ButtonGroup can be configured to be initially disabled via its `.Enable()` setting. The ButtonGroup can also be disabled or enabled at any time with JavaScript by using its `.Enable()` method with a Boolean argument. |
| 71 | + |
| 72 | +The example below demonstrates how to enable and disable the ButtonGroup. |
| 73 | + |
| 74 | +The following example demonstrates how to use `.Enable()`. |
| 75 | + |
| 76 | +###### Example |
| 77 | + |
| 78 | +``` |
| 79 | +
|
| 80 | + @(Html.Kendo().ButtonGroup() |
| 81 | + .Name("select-period") |
| 82 | + .Enable(false) |
| 83 | + .Items(t => |
| 84 | + { |
| 85 | + t.Add().Text("Month"); |
| 86 | + t.Add().Text("Quarter"); |
| 87 | + t.Add().Text("Year"); |
| 88 | + })) |
| 89 | +``` |
| 90 | + |
| 91 | +For more information on the [`enable` method of the ButtonGroup](http://docs.telerik.com/kendo-ui/api/javascript/ui/buttongroup#methods-enable), refer to the [API of the ButtonGroup control](http://docs.telerik.com/kendo-ui/api/javascript/ui/buttongroup). |
| 92 | + |
| 93 | +### Index |
| 94 | + |
| 95 | +Initially selected index of the Kendo UI ButtonGroup can be configured via its `index` property. An index could be selected via `select()` method with a Integer argument. |
| 96 | + |
| 97 | +The example below demonstrates how to select a button by its index. |
| 98 | + |
| 99 | +###### Example |
| 100 | + |
| 101 | +``` |
| 102 | +
|
| 103 | + @(Html.Kendo().ButtonGroup() |
| 104 | + .Name("select-period") |
| 105 | + .Index(1) |
| 106 | + .Items(t => |
| 107 | + { |
| 108 | + t.Add().Text("Month"); |
| 109 | + t.Add().Text("Quarter"); |
| 110 | + t.Add().Text("Year"); |
| 111 | + })) |
| 112 | +``` |
| 113 | + |
| 114 | +For more information on the [`index` setting of the ButtonGroup](http://docs.telerik.com/kendo-ui/api/javascript/ui/buttongroup#configuration-index), refer to the [API of the ButtonGroup control](http://docs.telerik.com/kendo-ui/api/javascript/ui/buttongroup). |
| 115 | + |
| 116 | + |
| 117 | +### Selection |
| 118 | + |
| 119 | +Kendo UI ButtonGroup can restrict the numbers of Buttons that can be selected via its `.Selection()` property. It can be configured with `single` or `multiple` selection. |
| 120 | + |
| 121 | +The following example demonstrates how to use `.Selection()`. |
| 122 | + |
| 123 | +###### Example |
| 124 | + |
| 125 | +``` |
| 126 | +
|
| 127 | + @(Html.Kendo().ButtonGroup() |
| 128 | + .Name("select-period") |
| 129 | + .Selection("multiple") |
| 130 | + .Items(t => |
| 131 | + { |
| 132 | + t.Add().Text("Month"); |
| 133 | + t.Add().Text("Quarter"); |
| 134 | + t.Add().Text("Year"); |
| 135 | + })) |
| 136 | +``` |
| 137 | + |
| 138 | +For more information on the [`selection` setting of the ButtonGroup](http://docs.telerik.com/kendo-ui/api/javascript/ui/buttongroup#configuration-selection), refer to the [API of the ButtonGroup control](http://docs.telerik.com/kendo-ui/api/javascript/ui/buttongroup). |
| 139 | + |
| 140 | +## Reference |
| 141 | + |
| 142 | +### Existing Instances |
| 143 | + |
| 144 | +For more information on how to access an instance, refer to the [introductory article on the ButtonGroup](http://docs.telerik.com/kendo-ui/controls/navigation/buttongroup/overview). |
| 145 | + |
| 146 | +## See Also |
| 147 | + |
| 148 | +* [JavaScript API Reference of the ButtonGroup](http://docs.telerik.com/kendo-ui/api/javascript/ui/buttongroup) |
| 149 | +* [ButtonGroup HtmlHelper for ASP.NET MVC](http://docs.telerik.com/aspnet-mvc/helpers/buttongroup/overview) |
| 150 | +* [ButtonGroup Official Demos](http://demos.telerik.com/aspnet-core/buttongroup/index) |
| 151 | +* [Overview of Telerik UI for ASP.NET Core]({% slug overview_aspnetmvc6_aspnetmvc %}) |
| 152 | +* [Get Started with Telerik UI for ASP.NET Core in ASP.NET Core Projects]({% slug gettingstarted_aspnetmvc6_aspnetmvc %}) |
| 153 | +* [Get Started with Telerik UI for ASP.NET Core in ASP.NET Core Projects on Linux]({% slug gettingstartedlinux_aspnetmvc6_aspnetmvc %}) |
| 154 | +* [Known Issues with Telerik UI for ASP.NET Core]({% slug knownissues_aspnetmvc6_aspnetmvc %}) |
0 commit comments