Hello,
I am trying to combine two of the demos into one application and I am running into trouble. I am doing the same thing as the RadGrid Hierarchy with Templates. When an item in the grid is selected and it loads the nesteditem, I want to load my tabs and pageviews dynamically with user controls as in the TabStrip / Load on Demand RadPageView demo. I am having a coupld of problems with this:
1. How can I add the tabs only to the item that is being selected from the grid? I have tried calling the addtab function from the ItemCreated and ItemDataBound methods of the RadGrid but of course it creates the tabs for every item (and also the pageview for the first tab) and I get the "multiple controls with the same ID" error. If I try to call the addtab from the ItemCommand method of the RadGrid, it works the first time through but as soon as I try to collapse the current item it throws the same error.
2. When the PageViewCreated method fires and loads the user control onto the page, I need to be able to set a public property of that user control. As it relates to the Telerik expample, I would need to be able to get the EmployeeID from the grid and assign it to the control (as the control needs that ID to load its data). At the point where the pageview is being created, I can't figure out how to find the EmployeeID for that particular grid item. I have tried using the DataKeyValues but I can't figure out how to get the index of the particular item that is selected on the grid as it is not being passed to the RadMultiPage controls PageViewCreated method.
Here is my aspx code:
And here is my codebehind:
I am trying to combine two of the demos into one application and I am running into trouble. I am doing the same thing as the RadGrid Hierarchy with Templates. When an item in the grid is selected and it loads the nesteditem, I want to load my tabs and pageviews dynamically with user controls as in the TabStrip / Load on Demand RadPageView demo. I am having a coupld of problems with this:
1. How can I add the tabs only to the item that is being selected from the grid? I have tried calling the addtab function from the ItemCreated and ItemDataBound methods of the RadGrid but of course it creates the tabs for every item (and also the pageview for the first tab) and I get the "multiple controls with the same ID" error. If I try to call the addtab from the ItemCommand method of the RadGrid, it works the first time through but as soon as I try to collapse the current item it throws the same error.
2. When the PageViewCreated method fires and loads the user control onto the page, I need to be able to set a public property of that user control. As it relates to the Telerik expample, I would need to be able to get the EmployeeID from the grid and assign it to the control (as the control needs that ID to load its data). At the point where the pageview is being created, I can't figure out how to find the EmployeeID for that particular grid item. I have tried using the DataKeyValues but I can't figure out how to get the index of the particular item that is selected on the grid as it is not being passed to the RadMultiPage controls PageViewCreated method.
Here is my aspx code:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> |
<AjaxSettings> |
<telerik:AjaxSetting AjaxControlID="RadGrid1"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
<telerik:AjaxSetting AjaxControlID="RadTabStrip1"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="RadTabStrip1" /> |
<telerik:AjaxUpdatedControl ControlID="RadMultiPage1" LoadingPanelID="RadAjaxLoadingPanel1" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
<telerik:AjaxSetting AjaxControlID="RadMultiPage1"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="RadMultiPage1" LoadingPanelID="RadAjaxLoadingPanel1" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
</AjaxSettings> |
</telerik:RadAjaxManager> |
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" /> |
<script type="text/javascript"> |
function onTabSelecting(sender, args) { |
if (args.get_tab().get_pageViewID()) { |
args.get_tab().set_postBack(false); |
} |
} |
</script> |
<h4>Attendee List</h4> |
<asp:ObjectDataSource ID="odsAttendeeList" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="dsAttendeeList" TypeName="WorkshopsLibrary.CAttendees"> |
<SelectParameters> |
<asp:SessionParameter Name="sUserID" SessionField="UserID" Type="String" /> |
<asp:SessionParameter Name="sWorkshopID" SessionField="AdminWorkshopID" Type="String" /> |
</SelectParameters> |
</asp:ObjectDataSource> |
<telerik:RadGrid ID="RadGrid1" DataSourceID="odsAttendeeList" runat="server" AutoGenerateColumns="False" AllowSorting="True" AllowMultiRowSelection="False" AllowPaging="True" PageSize="5" GridLines="None" ShowGroupPanel="true" OnPreRender="RadGrid1_PreRender"> |
<PagerStyle Mode="NumericPages" /> |
<MasterTableView DataSourceID="odsAttendeeList" DataKeyNames="RegistrationID" AllowMultiColumnSorting="True" GroupLoadMode="Server"> |
<NestedViewTemplate> |
<asp:Panel runat="server" ID="InnerContainer" CssClass="viewWrap" Visible="false"> |
<telerik:RadTabStrip ID="RadTabStrip1" SelectedIndex="0" CssClass="tabStrip" runat="server" MultiPageID="RadMultiPage1" Orientation="HorizontalTop" OnClientTabSelecting="onTabSelecting" OnTabClick="RadTabStrip1_TabClick" /> |
<telerik:RadMultiPage ID="RadMultiPage1" runat="server" SelectedIndex="0" CssClass="multiPage" OnPageViewCreated="RadMultiPage1_PageViewCreated" /> |
</asp:Panel> |
</NestedViewTemplate> |
<Columns> |
<telerik:GridBoundColumn SortExpression="RegistrationID" HeaderText="RegistrationID" HeaderButtonType="TextButton" DataField="RegistrationID" UniqueName="RegistrationID" /> |
<telerik:GridBoundColumn SortExpression="FirstName" HeaderText="First Name" HeaderButtonType="TextButton" DataField="FirstName" UniqueName="FirstName" /> |
<telerik:GridBoundColumn SortExpression="LastName" HeaderText="Last Name" HeaderButtonType="TextButton" DataField="LastName" UniqueName="LastName" /> |
<telerik:GridBoundColumn SortExpression="Citizenship" HeaderText="Citizenship" HeaderButtonType="TextButton" DataField="Citizenship" UniqueName="Citizenship" /> |
<telerik:GridBoundColumn SortExpression="Phone" HeaderText="Phone" HeaderButtonType="TextButton" DataField="Phone" UniqueName="Phone" /> |
<telerik:GridBoundColumn SortExpression="Email" HeaderText="Email" HeaderButtonType="TextButton" DataField="Email" UniqueName="Email" /> |
<telerik:GridBoundColumn SortExpression="Cancelled" HeaderText="Cancelled" HeaderButtonType="TextButton" DataField="Cancelled" UniqueName="Cancelled" /> |
<telerik:GridBoundColumn SortExpression="Accepted" HeaderText="Accepted" HeaderButtonType="TextButton" DataField="Accepted" UniqueName="Accepted" /> |
</Columns> |
</MasterTableView> |
<ClientSettings AllowDragToGroup="true" /> |
</telerik:RadGrid> |
And here is my codebehind:
Protected WithEvents RadTabStrip1 As RadTabStrip |
Protected WithEvents RadMultiPage1 As RadMultiPage |
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
Dim cPageRoutines As New CPageRoutines |
Dim cWorkshops As New CWorkshops |
If HttpContext.Current.Session("UserID") Is Nothing Then |
cPageRoutines.Login(User) |
End If |
cPageRoutines.VerifyRole("SystemAdministrator") |
cPageRoutines.VerifyAdminWorkshop("AdminWorkshopID") |
End Sub |
Private Sub AddPageView(ByVal tab As RadTab) |
For Each nestedItem As GridNestedViewItem In RadGrid1.MasterTableView.GetItems(GridItemType.NestedView) |
Dim RadMultiPage1 As RadMultiPage = DirectCast(nestedItem.FindControl("RadMultiPage1"), RadMultiPage) |
Dim pageView As RadPageView = New RadPageView |
pageView.ID = tab.Text.Replace(" ", "") |
RadMultiPage1.PageViews.Add(pageView) |
pageView.CssClass = "pageView" |
tab.PageViewID = pageView.ID |
Next |
End Sub |
Private Sub AddTab(ByVal tabName As String) |
For Each nestedItem As GridNestedViewItem In RadGrid1.MasterTableView.GetItems(GridItemType.NestedView) |
Dim RadTabStrip1 As RadTabStrip = DirectCast(nestedItem.FindControl("RadTabStrip1"), RadTabStrip) |
Dim tab As RadTab = New RadTab |
tab.Text = tabName |
RadTabStrip1.Tabs.Add(tab) |
Next |
End Sub |
Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs) Handles RadGrid1.PreRender |
If Not Page.IsPostBack Then |
RadGrid1.MasterTableView.Items(0).Expanded = False |
RadGrid1.MasterTableView.Items(0).ChildItem.FindControl("InnerContainer").Visible = True |
End If |
End Sub |
Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand |
If e.CommandName = RadGrid.ExpandCollapseCommandName Then |
DirectCast(e.Item, GridDataItem).ChildItem.FindControl("InnerContainer").Visible = Not e.Item.Expanded |
End If |
End Sub |
Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles RadGrid1.ItemCreated |
If TypeOf e.Item Is GridNestedViewItem Then |
e.Item.FindControl("InnerContainer").Visible = (DirectCast(e.Item, GridNestedViewItem)).ParentItem.Expanded |
Dim nestedItem As GridNestedViewItem = DirectCast(e.Item, GridNestedViewItem) |
Dim RadTabStrip1 As RadTabStrip = DirectCast(nestedItem.FindControl("RadTabStrip1"), RadTabStrip) |
AddTab("Attendee") |
AddPageView(RadTabStrip1.FindTabByText("Attendee")) |
AddTab("Additional Questions") |
Dim cCustomFields As New CCustomFields |
Dim dt As DataTable = cCustomFields.dsCustomFieldList(HttpContext.Current.Session("UserID").ToString, HttpContext.Current.Session("AdminWorkshopID").ToString).Tables(0) |
If dt.Rows.Count > 0 Then |
AddTab("Additional Questions") |
End If |
AddTab("Orders") |
AddTab("Payments") |
End If |
End Sub |
Protected Sub RadMultiPage1_PageViewCreated(ByVal sender As Object, ByVal e As RadMultiPageEventArgs) Handles RadMultiPage1.PageViewCreated |
Dim userControlName As String = e.PageView.ID & ".ascx" |
Dim userControl As Control = Page.LoadControl(userControlName) |
userControl.ID = e.PageView.ID & "_userControl" |
userControl.GetType().GetProperty("RegistrationID").SetValue(userControl, RadGrid1.MasterTableView.DataKeyValues(??)("RegistrationID").ToString, Nothing) |
e.PageView.Controls.Add(userControl) |
End Sub |
Protected Sub RadTabStrip1_TabClick(ByVal sender As Object, ByVal e As RadTabStripEventArgs) Handles RadTabStrip1.TabClick |
AddPageView(e.Tab) |
e.Tab.PageView.Selected = True |
End Sub |