The problem I'm having is that I want to have a command item template for each table at a level that will be a grant permissions link for that specific user entity.
This scenario seems problematic in that the ItemCreated event runs before the ItemDataBound event; is there some way around this?
Initially I was using DetailTables for this function but the templated display looks much better than the detail tables model.
Thanks,
Phil
7 Answers, 1 is accepted
| <telerik:RadGrid ID="UserListRadGrid" runat="server" OnItemCreated="RadGrid_ItemCreated" OnItemCommand="UserListRadGrid_ItemCommand" OnItemDataBound="UserListRadGrid_NodeDataBound" OnNeedDataSource="UserListRadGrid_NeedDataSource" OnDeleteCommand="UserListRadGrid_DeleteButton_Click" SkinID="ObjectList" GridLines="None" AutoGenerateColumns="False" AllowPaging="True" AllowCustomPaging="true" AllowMultiRowSelection="true" AllowSorting="True" PageSize="30" OnPreRender="UserListRadGrid_PreRender"> |
| <MasterTableView Name="UserView" CommandItemDisplay="Top" DataKeyNames="ObjectId" HierarchyLoadMode="ServerOnDemand"> |
| <NoRecordsTemplate> |
| <div> |
| There are no users to display</div> |
| </NoRecordsTemplate> |
| <CommandItemTemplate /> |
| <ExpandCollapseColumn Visible="True"> |
| </ExpandCollapseColumn> |
| <Columns> |
| <telerik:GridBoundColumn DataField="ObjectID" Display="False" UniqueName="ObjectID"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="IsActive" Display="False" UniqueName="IsActive"> |
| </telerik:GridBoundColumn> |
| <telerik:GridTemplateColumn SortExpression="UserName" HeaderText="       Login Name" UniqueName="UserNameColumn"> |
| <ItemTemplate> |
|   |
| <asp:Image runat="server" ImageAlign="absMiddle" ID="IconImage" /> |
| <asp:HyperLink runat="server" ID="NameLink" /> |
| </ItemTemplate> |
| <HeaderStyle Width="30%" /> |
| </telerik:GridTemplateColumn> |
| <telerik:GridBoundColumn EmptyDataText=" " SortExpression="FirstName" DataField="FirstName" HeaderText="First" UniqueName="FirstNameColumn"> |
| <HeaderStyle Width="15%" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn EmptyDataText=" " SortExpression="MiddleInitial" DataField="MiddleInitial" HeaderText="M" UniqueName="MiddleInitialColumn"> |
| <HeaderStyle Width="15px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn EmptyDataText=" " SortExpression="LastName" DataField="LastName" HeaderText="Last" UniqueName="LastNameColumn"> |
| <HeaderStyle Width="20%" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridDateTimeColumn DataField="LoginTime" SortExpression="LoginTime" DataType="System.DateTime" HeaderText="Last Log On" UniqueName="LastLogonColumn"> |
| <ItemStyle Wrap="False" /> |
| <HeaderStyle Width="125px" /> |
| </telerik:GridDateTimeColumn> |
| <telerik:GridTemplateColumn DataField="IsActive" UniqueName="IsActiveTemplate" HeaderText="All:"> |
| <ItemStyle Wrap="False" HorizontalAlign="Center" /> |
| <HeaderStyle HorizontalAlign="Right" Width="30px" /> |
| <ItemTemplate> |
| <LP:LPActivityControl runat="server" ID="ARDeactivateUsers1" ActivityClass="<%$ Resources:Activities, UserManager_Class %>" ActivityName="<%$ Resources:Activities, UserManager_EditUsers_Right %>"> |
| <asp:ImageButton runat="server" ID="UserStatusChanger" OnCommand="StatusChange_Command" /></LP:LPActivityControl> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridClientSelectColumn UniqueName="RevokeCheck"> |
| <HeaderStyle Width="10px" /> |
| </telerik:GridClientSelectColumn> |
| </Columns> |
| <NestedViewTemplate> |
| <asp:Panel ID="UserAccountsPanel" runat="server"> |
| <fieldset class="ChildTableFirst"> |
| <legend class="ChildTableHeader">Assigned Accounts</legend> |
| <telerik:RadGrid runat="server" ID="AccountListRadGrid" SkinID="ObjectList" AutoGenerateColumns="false" GridLines="none" AllowPaging="True" AllowCustomPaging="true" AllowMultiRowSelection="true" AllowSorting="True" PageSize="30" OnItemCreated="RadGrid_ItemCreated"> |
| <MasterTableView Name="AccountsForUser" CommandItemDisplay="Top"> |
| <CommandItemTemplate> |
| <table class="Object_ListHeader_Table LightBluePanel" cellpadding="2" cellspacing="0"> |
| <tr> |
| <td class="FilterOptions"> |
| <asp:Label ID="showingassignedaccounts" Text="Showing: assigned accounts" runat="server" /> |
| </td> |
| <td style="text-align: right;"> |
| <LP:LPActivityControl runat="server" ID="ARCGrantAccounts" ActivityClass="<%$ Resources:Activities, AccountAdmin_Class %>" ActivityName="<%$ Resources:Activities, AccountAdmin_EditAccountSecurity_Right %>"> |
| <asp:ImageButton ImageUrl="<%$ Resources:Imgs_Accounts, Bttn_GrantAccountAccess %>" ID="GrantAccountResources_Image" ImageAlign="AbsMiddle" runat="server" ToolTip="grant this user access to additional accounts" /> |
| <asp:LinkButton CssClass="Object_Command" ID="GrantAccountResources_Button" runat="server" Text="Grant..." ToolTip="grant this user access to additional accounts"></asp:LinkButton></LP:LPActivityControl> |
| </td> |
| </tr> |
| </table> |
| </CommandItemTemplate> |
| <Columns> |
| <telerik:GridBoundColumn DataField="ObjectId" UniqueName="ObjectId" HeaderText="ObjectId"></telerik:GridBoundColumn> |
| <telerik:GridTemplateColumn HeaderText="Account Name" UniqueName="TemplateColumn"> |
| <ItemStyle Width="100%" /> |
| <ItemTemplate> |
| <asp:Image runat="server" ID="AccountImage" ImageUrl="<%$ Resources:Imgs_Accounts, Icon_AccountObject %>" /> |
| <asp:HyperLink runat="server" ID="AccountLink" /> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridTemplateColumn HeaderText="" UniqueName="ReactivateColumn"> |
| <ItemStyle Width="40px" /> |
| <ItemTemplate> |
| <LP:LPActivityControl runat="server" ID="ARActivateAccountImage" ActivityClass="<%$ Resources:Activities, AccountAdmin_Class %>" ActivityName="<%$ Resources:Activities, AccountAdmin_EditAccountSecurity_Right %>"> |
| <asp:ImageButton runat="server" ID="AccountReactivate" AlternateText="activate account" CommandName="ReactivateAccount" ImageUrl="<%$ Resources:Imgs_Accounts, Bttn_ReactivateAccount %>" OnCommand="StatusChange_Command" Visible="false" /></LP:LPActivityControl> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| </Columns> |
| </MasterTableView> |
| </telerik:RadGrid> |
| </fieldset> |
| </asp:Panel> |
| <asp:Panel ID="UserPagesPanel" runat="server"> |
| <fieldset class="ChildTable"> |
| <legend class="ChildTableHeader">Assigned Pages</legend> |
| <telerik:RadGrid runat="server" ID="PageListRadGrid" SkinID="ObjectList" AutoGenerateColumns="false" GridLines="none" AllowPaging="True" AllowCustomPaging="true" AllowMultiRowSelection="true" AllowSorting="True" PageSize="30" OnItemCreated="RadGrid_ItemCreated"> |
| <MasterTableView Name="PagesForUser" CommandItemDisplay="top"> |
| <CommandItemTemplate> |
| <table class="Object_ListHeader_Table LightBluePanel" cellpadding="2" cellspacing="0"> |
| <tr> |
| <td class="FilterOptions"> |
| <asp:Label ID="showingassignedpages" Text="Showing: assigned pages" runat="server" /> |
| </td> |
| <td style="text-align: right;"> |
| <asp:ImageButton ImageUrl="<%$ Resources:Imgs_WebPortal, Bttn_Add_GrantPageAccess %>" ID="GrantPageResources_Image" ImageAlign="AbsMiddle" runat="server" ToolTip="grant this user access to additional pages" /> |
| <asp:LinkButton CssClass="Object_Command" ID="GrantPageResources_Button" runat="server" Text="Grant..." ToolTip="grant this user access to additional pages"></asp:LinkButton> |
| </td> |
| </tr> |
| </table> |
| </CommandItemTemplate> |
| <Columns> |
| <telerik:GridBoundColumn DataField="ObjectId" UniqueName="ObjectId" HeaderText="ObjectId"></telerik:GridBoundColumn> |
| <telerik:GridTemplateColumn HeaderText="Page Name" UniqueName="TemplateColumn"> |
| <ItemTemplate> |
| <asp:Image runat="server" ID="PageImage" ImageUrl="<%$ Resources:Imgs_WebPortal, Icon_PageObject %>" /> |
| <asp:HyperLink runat="server" ID="PageLink" /> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| </Columns> |
| </MasterTableView> |
| </telerik:RadGrid> |
| </fieldset> |
| </asp:Panel> |
| <asp:Panel ID="UserGroupsPanel" runat="server"> |
| <fieldset class="ChildTableLast"> |
| <legend class="ChildTableHeader">Assigned Groups</legend> |
| <telerik:RadGrid runat="server" ID="GroupListRadGrid" SkinID="ObjectList" AutoGenerateColumns="false" GridLines="none" AllowPaging="True" AllowCustomPaging="true" AllowMultiRowSelection="true" AllowSorting="True" PageSize="30"> |
| <MasterTableView Name="GroupsForUser" CommandItemDisplay="top"> |
| <CommandItemTemplate> |
| <table class="Object_ListHeader_Table LightBluePanel" cellpadding="2" cellspacing="0"> |
| <tr> |
| <td class="FilterOptions"> |
| <asp:Label ID="showinggroupmembership" Text="Showing: group membership" runat="server" /> |
| </td> |
| <td style="text-align: right;"> |
| <LP:LPActivityControl runat="server" ID="ARCGrantAccounts" ActivityClass="<%$ Resources:Activities, UserManager_Class %>" ActivityName="<%$ Resources:Activities, UserManager_EditGroups_Right %>"> |
| <asp:ImageButton ImageUrl="<%$ Resources:Imgs_Accounts, Bttn_GrantAccountAccess %>" ID="GrantGroupMembership_Image" ImageAlign="AbsMiddle" runat="server" ToolTip="grant this user membership to other groups" /> |
| <asp:LinkButton CssClass="Object_Command" ID="GrantGroupResources_Button" runat="server" Text="Grant..." ToolTip="grant this user membership to additional groups"></asp:LinkButton></LP:LPActivityControl> |
| </td> |
| </tr> |
| </table> |
| </CommandItemTemplate> |
| <Columns> |
| <telerik:GridBoundColumn DataField="ObjectId" UniqueName="ObjectId" HeaderText="ObjectId"></telerik:GridBoundColumn> |
| <telerik:GridTemplateColumn HeaderText="Group Name" DataField="Name" UniqueName="GroupName"> |
| <ItemTemplate> |
| <asp:Image runat="server" ID="GroupImage" ImageUrl="<%$ Resources: Imgs_UserMgmt, Icon_GroupObject %>" /> |
| <asp:HyperLink runat="server" ID="GroupLink" /> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridBoundColumn DataField="UserCount" HeaderText="User Count" UniqueName="UserCount"> |
| </telerik:GridBoundColumn> |
| </Columns> |
| </MasterTableView> |
| </telerik:RadGrid> |
| </fieldset> |
| </asp:Panel> |
| </NestedViewTemplate> |
| <%--<DetailTables> |
| <telerik:GridTableView DataKeyNames="ObjectID" Name="AccountsForUser" PageSize="5" runat="server" CommandItemDisplay="Top"> |
| <CommandItemTemplate> |
| <table class="Object_ListHeader_Table LightBluePanel" cellpadding="2" cellspacing="0"> |
| <tr> |
| <td class="FilterOptions"> |
| <asp:Label ID="showingassignedaccounts" Text="Showing: assigned accounts" runat="server" /> |
| </td> |
| <td style="text-align: right;"> |
| <LP:LPActivityControl runat="server" ID="ARCGrantAccounts" ActivityClass="<%$ Resources:Activities, AccountAdmin_Class %>" ActivityName="<%$ Resources:Activities, AccountAdmin_EditAccountSecurity_Right %>"> |
| <asp:ImageButton ImageUrl="<%$ Resources:Imgs_Accounts, Bttn_GrantAccountAccess %>" ID="GrantAccountResources_Image" ImageAlign="AbsMiddle" runat="server" ToolTip="grant this user access to additional accounts" /> |
| <asp:LinkButton CssClass="Object_Command" ID="GrantAccountResources_Button" runat="server" Text="Grant..." ToolTip="grant this user access to additional accounts"></asp:LinkButton></LP:LPActivityControl> |
| </td> |
| </tr> |
| </table> |
| </CommandItemTemplate> |
| <Columns> |
| <telerik:GridTemplateColumn HeaderText="Account Name" UniqueName="TemplateColumn"> |
| <ItemStyle Width="100%" /> |
| <ItemTemplate> |
| <asp:Image runat="server" ID="AccountImage" ImageUrl="<%$ Resources:Imgs_Accounts, Icon_AccountObject %>" /> |
| <asp:HyperLink runat="server" ID="AccountLink" /> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridTemplateColumn HeaderText="" UniqueName="ReactivateColumn"> |
| <ItemStyle Width="40px" /> |
| <ItemTemplate> |
| <LP:LPActivityControl runat="server" ID="ARActivateAccountImage" ActivityClass="<%$ Resources:Activities, AccountAdmin_Class %>" ActivityName="<%$ Resources:Activities, AccountAdmin_EditAccountSecurity_Right %>"> |
| <asp:ImageButton runat="server" ID="AccountReactivate" AlternateText="activate account" CommandName="ReactivateAccount" ImageUrl="<%$ Resources:Imgs_Accounts, Bttn_ReactivateAccount %>" OnCommand="StatusChange_Command" Visible="false" /></LP:LPActivityControl> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| </Columns> |
| </telerik:GridTableView> |
| <telerik:GridTableView DataKeyNames="ObjectID" Name="GroupsForUser" PageSize="5" runat="server" CommandItemDisplay="top"> |
| <CommandItemTemplate> |
| <table class="Object_ListHeader_Table LightBluePanel" cellpadding="2" cellspacing="0"> |
| <tr> |
| <td class="FilterOptions"> |
| <asp:Label ID="showinggroupmembership" Text="Showing: group membership" runat="server" /> |
| </td> |
| <td style="text-align: right;"> |
| <LP:LPActivityControl runat="server" ID="ARCGrantAccounts" ActivityClass="<%$ Resources:Activities, UserManager_Class %>" ActivityName="<%$ Resources:Activities, UserManager_EditGroups_Right %>"> |
| <asp:ImageButton ImageUrl="<%$ Resources:Imgs_Accounts, Bttn_GrantAccountAccess %>" ID="GrantGroupMembership_Image" ImageAlign="AbsMiddle" runat="server" ToolTip="grant this user membership to other groups" /> |
| <asp:LinkButton CssClass="Object_Command" ID="GrantGroupResources_Button" runat="server" Text="Grant..." ToolTip="grant this user membership to additional groups"></asp:LinkButton></LP:LPActivityControl> |
| </td> |
| </tr> |
| </table> |
| </CommandItemTemplate> |
| <Columns> |
| <telerik:GridTemplateColumn HeaderText="Group Name" DataField="Name" UniqueName="GroupName"> |
| <ItemTemplate> |
| <asp:Image runat="server" ID="GroupImage" ImageUrl="<%$ Resources: Imgs_UserMgmt, Icon_GroupObject %>" /> |
| <asp:HyperLink runat="server" ID="GroupLink" /> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridBoundColumn DataField="UserCount" HeaderText="User Count" UniqueName="UserCount"> |
| </telerik:GridBoundColumn> |
| </Columns> |
| </telerik:GridTableView> |
| <telerik:GridTableView DataKeyNames="ObjectID" Name="PagesForUser" PageSize="5" runat="server" CommandItemDisplay="top"> |
| <CommandItemTemplate> |
| <table class="Object_ListHeader_Table LightBluePanel" cellpadding="2" cellspacing="0"> |
| <tr> |
| <td class="FilterOptions"> |
| <asp:Label ID="showingassignedpages" Text="Showing: assigned pages" runat="server" /> |
| </td> |
| <td style="text-align: right;"> |
| <asp:ImageButton ImageUrl="<%$ Resources:Imgs_WebPortal, Bttn_Add_GrantPageAccess %>" ID="GrantPageResources_Image" ImageAlign="AbsMiddle" runat="server" ToolTip="grant this user access to additional pages" /> |
| <asp:LinkButton CssClass="Object_Command" ID="GrantPageResources_Button" runat="server" Text="Grant..." ToolTip="grant this user access to additional pages"></asp:LinkButton> |
| </td> |
| </tr> |
| </table> |
| </CommandItemTemplate> |
| <Columns> |
| <telerik:GridTemplateColumn HeaderText="Page Name" UniqueName="TemplateColumn"> |
| <ItemTemplate> |
| <asp:Image runat="server" ID="PageImage" ImageUrl="<%$ Resources:Imgs_WebPortal, Icon_PageObject %>" /> |
| <asp:HyperLink runat="server" ID="PageLink" /> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| </Columns> |
| </telerik:GridTableView> |
| </DetailTables>--%> |
| <SortExpressions> |
| <telerik:GridSortExpression FieldName="UserName" /> |
| </SortExpressions> |
| </MasterTableView> |
| <PagerStyle PagerTextFormat="Page {0} of {1}     |     {4} |     Items {2} to {3} of {5}" BackColor="#F0F0F0" /> |
| <FilterMenu EnableTheming="True"> |
| <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> |
| </FilterMenu> |
| <ClientSettings> |
| <Selecting AllowRowSelect="True" /> |
| </ClientSettings> |
| </telerik:RadGrid> |
| protected void RadGrid_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) |
| { |
| if (e.Item is GridCommandItem) |
| { |
| Guid consumerId = Guid.Empty; //Need the parent fow guid. |
| if (e.Item.OwnerTableView.Name == "AccountsForUser") |
| { |
| LPQueryStringBuilder builder = new LPQueryStringBuilder(SecInfo); |
| builder.AddItem("Id", consumerId.ToString(), LPQueryStringType.Guid); |
| string link = string.Concat("javascript:Include_Account_Resources('", GetAssignUserAccountsUrl(), "?Token=", Server.UrlEncode(builder.GetEncryptedQueryString()), "');return false"); |
| LinkButton grantButton = e.Item.FindControl("GrantAccountResources_Button") as LinkButton; |
| grantButton.OnClientClick = link; |
| } |
| if (e.Item.OwnerTableView.Name == "PagesForUser") |
| { |
| //Guid userId = new Guid(e.Item.OwnerTableView.ParentItem["ObjectId"].Text); |
| LPQueryStringBuilder builder = new LPQueryStringBuilder(SecInfo); |
| builder.AddItem("Id", consumerId.ToString(), LPQueryStringType.Guid); |
| string link = string.Concat("javascript:Include_Page_Resources('", GetAssignUserPagesUrl(), "?Token=", builder.GetEncryptedQueryString(), "');return false"); |
| LinkButton grantButton = e.Item.FindControl("GrantPageResources_Button") as LinkButton; |
| grantButton.OnClientClick = link; |
| } |
| if (e.Item.OwnerTableView.Name == "GroupsForUser") |
| { |
| //Guid userId = new Guid(e.Item.OwnerTableView.ParentItem["ObjectId"].Text); |
| LPQueryStringBuilder builder = new LPQueryStringBuilder(SecInfo); |
| builder.AddItem("Id", consumerId.ToString(), LPQueryStringType.Guid); |
| string link = string.Concat("javascript:Include_Group_Membership('", GetAssignGroupsToUserUrl(), "?Token=", builder.GetEncryptedQueryString(), "');return false"); |
| LinkButton grantButton = e.Item.FindControl("GrantGroupResources_Button") as LinkButton; |
| grantButton.OnClientClick = link; |
| } |
| } |
| } |
ItemCreated always fires before ItemDataBound for all items and there is no way around it. Logically speaking, there is no way you can bind an item before you create it first. If you tell us what problems do you face in using those two events, we might be able to suggest a better approach.
Greetings,
Veli
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
For more detail I'm making an app-layer call in my n-tier system to a method like GetUsersForSite(SiteID) and on the subsequent nested table creating a method like GetAccountsForUser(UserID) where UserID would be the data key of the parent row. This all works fine with the nested templates; but I'm opening a grant account rights window (radwindow) that gets created when the template is created and uses as argument an encrypted UserID.
When the nested radgrid template is created it doesn't appear to know anything about the parent radgrid's row, so when child radgrid's command item template is created I can't specify the url to the radwindow with the encrypted userid as a querystring value.
Any suggestions would be great; but being able to have templated or skin-able detail tables at some point later could be useful (if it's not already possible).
Thanks,
Phil
If I understood you correctly, you need 2 things.
1. To replace the NestedTableView layout with another layout. You can use the NestedViewTemplate feature of the GridTableView to define your own controls and layout in the nested item:
2. To get to the parent item's data key value from a child table. If you are currently using the DetailTableDataBind event to bind your nested table, e.DetailTableView.ParentItem.GetDataKeyValue() is probably what you need. It gives you access to the key values of the parent GridDataItem whose child table you are currently binding.
Alternatively, if you do not use this event, you need to somehow get reference to the GridNestedViewItem instance containing your nested table. The former is the nested item that is shown below the data item you have expanded in RadGrid, and it contains your nested table. The GridNestedViewItem has a ParentItem property that references, again, the parent GridDataItem, whose GetDataKeyValue() method you can use. Supposing you need to get reference to the latter in ItemCreated/ItemDataBound, you would do :
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e){ if (e.Item is GridNestedViewItem) { GridNestedViewItem item = e.Item as GridNestedViewItem; item.ParentItem.GetDataKeyValue() }}If I understand you correctly, you want to access the parent item's data key value and use it to set a command in the CommandItem of your nested table. This can, again be done in ItemCreated/ItemDataBound events:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e){ if (e.Item is GridCommandItem && e.Item.OwnerTableView != RadGrid1.MasterTableView) { GridCommandItem item = e.Item as GridCommandItem; item.OwnerTableView.ParentItem.GetDataKeyValue() }}Regards,
Veli
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I'm trying replace the detailtables with a nestedtemplateview. Are you saying these two concepts can work together? The documentation seems to say otherwise, am I missing a concept there?
| Note that when you set NestedView template at a given level the regular detail tables definitions you may have at the same level will be disregarded. |
I currently have the detailtables working, but I don't like the look of the detailtable views. I'd rather use the nestedtemplateview; but during the itemcreated event of the commanditemtemplate of the nestedtemplateview radgrid the ownertableview.parentitem is null.
What you read is correct. You can use either the detail tables, or the NestedViewTemplate. The two are interchangable, but cannot be mixed together? Have I implied otherwise?
Greetings,
Veli
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I think I've got it figured out... Unless you've got a better solution.
User Control for asp.net page(s):
| <%@ Control Language="C#" AutoEventWireup="true" CodeFile="NestedViewControl.ascx.cs" Inherits="Controls_NestedViewControl" %> |
| <div> |
| <telerik:RadGrid runat="server" ID="NestedParent" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" GridLines="None" OnNeedDataSource="NestedParent_NeedDataSource" OnItemCommand="NestedParent_ItemCommand" OnItemCreated="NestedParent_ItemCreated" Skin="Web20"> |
| <MasterTableView DataKeyNames="Id"> |
| <ExpandCollapseColumn Visible="True"> |
| </ExpandCollapseColumn> |
| <Columns> |
| <telerik:GridBoundColumn UniqueName="ParentId" HeaderText="Parent Id" DataField="ParentId" DataType="System.Guid"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn UniqueName="Id" HeaderText="Id" DataField="Id" DataType="System.Guid"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn UniqueName="DateCreated" HeaderText="Date Created" DataType="System.DateTime"> |
| </telerik:GridBoundColumn> |
| </Columns> |
| <NestedViewTemplate> |
| <fieldset style="padding: 5px;"> |
| <legend style="padding: 5px;">Child TestObjects</legend> |
| <telerik:RadGrid runat="server" ID="NestedChild" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" GridLines="None" OnItemCreated="NestedChild_ItemCreated" Skin="Sunset"> |
| <MasterTableView CommandItemDisplay="top"> |
| <CommandItemTemplate> |
| <asp:Label ID="ParentIdValue" runat="server"></asp:Label> |
| </CommandItemTemplate> |
| <RowIndicatorColumn> |
| <HeaderStyle Width="20px" /> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn> |
| <HeaderStyle Width="20px" /> |
| </ExpandCollapseColumn> |
| <Columns> |
| <telerik:GridBoundColumn UniqueName="ParentId" HeaderText="Parent Id" DataField="ParentId" DataType="System.Guid"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn UniqueName="Id" HeaderText="Id" DataField="Id" DataType="System.Guid"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn UniqueName="DateCreated" HeaderText="Date Created" DataType="System.DateTime"> |
| </telerik:GridBoundColumn> |
| </Columns> |
| </MasterTableView> |
| </telerik:RadGrid> |
| </fieldset> |
| </NestedViewTemplate> |
| </MasterTableView> |
| </telerik:RadGrid> |
| </div> |
User Control Code Behind:
| using System; |
| using System.Data; |
| using System.Configuration; |
| using System.Collections; |
| using System.Web; |
| using System.Web.Security; |
| using System.Web.UI; |
| using System.Web.UI.WebControls; |
| using System.Web.UI.WebControls.WebParts; |
| using System.Web.UI.HtmlControls; |
| using System.Collections.Generic; |
| using Telerik.Web.UI; |
| public partial class Controls_NestedViewControl : System.Web.UI.UserControl |
| { |
| private Guid _ExpandedParentId; |
| public Guid ExpandedParentId |
| { |
| get { return _ExpandedParentId; } |
| set { _ExpandedParentId = value; } |
| } |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| } |
| protected void NestedParent_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) |
| { |
| List<TestObject> tester = TestObject.Create(300); |
| NestedParent.DataSource = tester; |
| } |
| protected void NestedParent_ItemCreated(object sender, GridItemEventArgs e) |
| { |
| } |
| protected void NestedChild_ItemCreated(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridCommandItem && e.Item.OwnerTableView != NestedParent.MasterTableView) |
| { |
| GridCommandItem item = e.Item as GridCommandItem; |
| Label label = e.Item.FindControl("ParentIdValue") as Label; |
| label.Text = ExpandedParentId.ToString(); |
| } |
| } |
| protected void NestedParent_ItemCommand(object source, GridCommandEventArgs e) |
| { |
| if (e.CommandName == RadGrid.ExpandCollapseCommandName) |
| { |
| RadGrid grid = ((RadGrid)((GridDataItem)e.Item).ChildItem.FindControl("NestedChild")); |
| ExpandedParentId = new Guid(e.Item.OwnerTableView.Items[e.Item.ItemIndex]["Id"].Text); |
| List<TestObject> items = TestObject.Create(300, ExpandedParentId); |
| grid.DataSource = items; |
| grid.DataBind(); |
| } |
| } |
| } |
Sample Entity Object:
| using System; |
| using System.Data; |
| using System.Configuration; |
| using System.Web; |
| using System.Web.Security; |
| using System.Web.UI; |
| using System.Web.UI.WebControls; |
| using System.Web.UI.WebControls.WebParts; |
| using System.Web.UI.HtmlControls; |
| using System.Collections.Generic; |
| /// <summary> |
| /// Summary description for TestObject |
| /// </summary> |
| public class TestObject |
| { |
| private DateTime _DateCreated; |
| private Guid _Id; |
| private Guid _ParentId; |
| public DateTime DateCreated |
| { |
| get { return _DateCreated; } |
| } |
| public Guid Id |
| { |
| get { return _Id; } |
| } |
| public Guid ParentId |
| { |
| get { return _ParentId; } |
| } |
| protected TestObject() |
| { |
| _Id = Guid.NewGuid(); |
| _DateCreated = DateTime.Now; |
| } |
| protected TestObject(Guid parentId) |
| { |
| _Id = Guid.NewGuid(); |
| _DateCreated = DateTime.Now; |
| _ParentId = parentId; |
| } |
| public static List<TestObject> Create(int numberOfTestObjects) |
| { |
| List<TestObject> tester = new List<TestObject>(); |
| int count = 0; |
| do |
| { |
| tester.Add(new TestObject()); |
| } |
| while (++count < numberOfTestObjects); |
| return tester; |
| } |
| public static List<TestObject> Create(int numberOfTestObjects, Guid parentId) |
| { |
| List<TestObject> tester = new List<TestObject>(); |
| int count = 0; |
| do |
| { |
| tester.Add(new TestObject(parentId)); |
| } |
| while (++count < numberOfTestObjects); |
| return tester; |
| } |
| } |