<%@ Page Language="VB" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs)
        RadGrid1.DataSource = New Object() {1, 2, 3}
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

        <script type="text/javascript">
            var Button1ClientID = '<%= RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)(0).FindControl("Button1").ClientID %>';

            function pageLoad(sender, args) {
                ToggleDisabledState();
            }

            function RowSelected(sender, args) {
                ToggleDisabledState();
            }

            function RowDeselected(sender, args) {
                ToggleDisabledState();
            }

            function ToggleDisabledState() {
                if ($find("<%= RadGrid1.ClientID %>").get_selectedItems().length == 0) {
                    $get(Button1ClientID).disabled = "disabled";
                }
                else {
                    $get(Button1ClientID).disabled = "";
                }
            }
        </script>

    </telerik:RadCodeBlock>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowMultiRowSelection="true" OnNeedDataSource="RadGrid1_NeedDataSource">
            <MasterTableView CommandItemDisplay="Top">
                <CommandItemTemplate>
                    <asp:Button ID="Button1" Text="Edit selected items" CommandName="EditSelected" runat="server" />
                </CommandItemTemplate>
                <Columns>
                    <telerik:GridClientSelectColumn />
                </Columns>
            </MasterTableView>
            <ClientSettings>
                <Selecting AllowRowSelect="true" />
                <ClientEvents OnRowSelected="RowSelected" OnRowDeselected="RowDeselected" />
            </ClientSettings>
        </telerik:RadGrid>
    </div>
    </form>
</body>
</html>
