<%@ Page Language="C#" %>

<%@ Register Namespace="Telerik.Web.UI" TagPrefix="telerik" 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 void RadGrid1_ItemDeleted(object source, GridDeletedEventArgs e)
    {
        if ((e.Item.OwnerTableView.Items.Count - 1) == 0)
        {
            RadGrid1.CurrentPageIndex = 0;
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <asp:LinqDataSource runat="server" ID="LinqDataSource1" ContextTypeName="LinksClassesDataContext"
            TableName="Things" EnableDelete="True" EnableInsert="True" EnableUpdate="true"
            OrderBy="ParentId">
        </asp:LinqDataSource>
        <telerik:RadGrid Skin="Vista" AutoGenerateDeleteColumn="true" AutoGenerateEditColumn="true"
            GroupingEnabled="true" ShowGroupPanel="true" runat="server" DataSourceID="LinqDataSource1"
            AllowAutomaticDeletes="true" AllowAutomaticInserts="true" AllowAutomaticUpdates="true"
            AllowPaging="true" PageSize="12" AllowSorting="true" AllowFilteringByColumn="true"
            ID="RadGrid1" onitemdeleted="RadGrid1_ItemDeleted">
            <MasterTableView DataKeyNames="Id" CommandItemDisplay="Top">                
            </MasterTableView>
            <ClientSettings AllowColumnsReorder="true" AllowDragToGroup="true">
            </ClientSettings>
        </telerik:RadGrid>
    </div>
    </form>
</body>
</html>
