Hi,
I am trying to have a radgrid working after having rows added or removed from it.
The scenario is the following :
I want to be able to add items that are selected in a grid (QuestionsGrid1) located in a bootstrap modal. Once applied, the code behind adds the new items
to the main radgrid (QuestionsGrid) in a multipageview.
The issue is that once a postback is done, the system is not able to find the control of the main grid (QuestionsGrid), and no matter what I do, i continuously get this error :
"Uncaught TypeError: Cannot set property 'control' of undefined"
Here is the ASPX code and the C# Code.
Thanks for help.
ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="theme.aspx.cs" Inherits="WBT.manageQuiz.theme" %><%@ Register Src="~/controls/admin/metaheader.ascx" TagName="MetaHeader" TagPrefix="WBT" %><%@ Register Src="~/controls/admin/header.ascx" TagName="Header" TagPrefix="WBT" %><%@ Register Src="~/controls/admin/menu.ascx" TagName="Menu" TagPrefix="WBT" %><%@ Register Src="~/controls/admin/pagecontentheader.ascx" TagName="ContentHeader" TagPrefix="WBT" %><%@ Register Src="~/controls/admin/footer.ascx" TagName="Footer" TagPrefix="WBT" %><!DOCTYPE html><!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]--><!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]--><!--[if !IE]><!--><html lang="en"><!--<![endif]--><head id="wbtHeader" runat="server"> <title><%=Session["WBTPageTitle"]%></title> <WBT:MetaHeader ID="metaheader" runat="server" /></head><body class="page-header-fixed page-sidebar-closed-hide-logo page-container-bg-solid page-md page-wbt"> <form id="wbtform" runat="server"> <telerik:RadSkinManager ID="PageSkinManager" runat="server" ShowChooser="false" /> <telerik:RadScriptManager ID="PageRadScriptManager" runat="server" EnablePartialRendering="true"> <Scripts> <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" /> <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" /> <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" /> </Scripts> </telerik:RadScriptManager> <telerik:RadAjaxManager ID="PageRadAjaxManager" runat="server" OnAjaxRequest="PageRadAjaxManager_AjaxRequest"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="PageRadAjaxManager"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="QuestionsGrid1" LoadingPanelID="RadAjaxLoadingPanel" /> <telerik:AjaxUpdatedControl ControlID="QuestionsGrid" LoadingPanelID="RadAjaxLoadingPanel" /> <telerik:AjaxUpdatedControl ControlID="QuestionFolderRadTreeView" LoadingPanelID="RadAjaxLoadingPanel" /> <telerik:AjaxUpdatedControl ControlID="RadPageView1" LoadingPanelID="RadAjaxLoadingPanel" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="RadTabTheme"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadMultiPageTheme" LoadingPanelID="RadAjaxLoadingPanel" /> <telerik:AjaxUpdatedControl ControlID="RadTabTheme" LoadingPanelID="RadAjaxLoadingPanel" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="RadMultiPageTheme"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadMultiPageTheme" LoadingPanelID="RadAjaxLoadingPanel" /> <telerik:AjaxUpdatedControl ControlID="RadTabTheme" LoadingPanelID="RadAjaxLoadingPanel" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="QuestionFolderRadTreeView"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="QuestionFolderRadTreeView" LoadingPanelID="RadAjaxLoadingPanel" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="QuestionsGrid1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="QuestionsGrid1" LoadingPanelID="RadAjaxLoadingPanel" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="QuestionsGrid"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="QuestionsGrid" LoadingPanelID="RadAjaxLoadingPanel" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <telerik:RadScriptBlock ID="PageRadScriptBlock" runat="server"> <script type="text/javascript"> var selected = []; var dSelected = []; /*DEPRECATED*/ /* NEEDED FOR BINDING CONTROL */ /*DEPRECATED*/ function openModal() { $('.modal.fade').css({ "-webkit-transition": "opacity 0.5s" }); $('#responsive').modal('show'); $('.modal.fade').css({ "-webkit-transition": "opacity 0.3s linear, top 0.3s ease-out, bottom 0.3s ease-out, margin-top 0.3s ease-out", "-moz-transition":"opacity 0.3s linear, top 0.3s ease-out, bottom 0.3s ease-out, margin-top 0.3s ease-out", "-o-transition":"opacity 0.3s linear, top 0.3s ease-out, bottom 0.3s ease-out, margin-top 0.3s ease-out", "transition":"opacity 0.3s linear, top 0.3s ease-out, bottom 0.3s ease-out, margin-top 0.3s ease-out", "overflow":"visible" }); } /* NEEDED FOR BINDING CONTROL */ function btnShowAll_Click() { var ajaxManager = $find("<%=PageRadAjaxManager.ClientID%>"); var wbtAjaxArgs = 'ClearFilters||'; ajaxManager.ajaxRequest(wbtAjaxArgs); } function bindQuestions() { var ajaxManager = $find("<%=PageRadAjaxManager.ClientID%>"); var wbtAjaxArgs = 'AddQuestionsTheme||'; for(i = 0; i < selected.length; i++) { if (selected[i]) { wbtAjaxArgs += i + "|"; } } selected = []; ajaxManager.ajaxRequest(wbtAjaxArgs); } function UnbindQuestions() { var ajaxManager = $find("<%=PageRadAjaxManager.ClientID%>"); var wbtAjaxArgs = 'DropQuestionsTheme||'; for(i = 0; i < dSelected.length; i++) { if (dSelected[i]) { wbtAjaxArgs += i + "|"; } } dSelected = []; ajaxManager.ajaxRequest(wbtAjaxArgs); } function DisplaySelected() { for(i = 0; i < selected.length; i++) { if (selected[i]) { console.log(i); } } } function QuestionsGrid1_RowSelected(sender, args) { var ID = args.getDataKeyValue("ID"); if (!selected[ID]) { selected[ID] = true; } } function QuestionsGrid1_RowDeselected(sender, args) { var ID = args.getDataKeyValue("ID"); if (selected[ID]) { selected[ID] = false; } } function QuestionsGrid_RowSelected(sender, args) { var ID = args.getDataKeyValue("ID"); if (!dSelected[ID]) { dSelected[ID] = true; } } function QuestionsGrid_RowDeselected(sender, args) { var ID = args.getDataKeyValue("ID"); if (dSelected[ID]) { dSelected[ID] = false; } } function pageLoad(sender,args) { var dataItems = $find('<%=QuestionsGrid1.ClientID %>').get_masterTableView().get_dataItems(); if (dataItems != null) { for (var i = 0, j = dataItems.length; i < j; i++) { var item = dataItems[i]; if (selected[item.getDataKeyValue("ID")]) { item.set_selected(true); } } } } function ApplyQuestionFolder() { var treeId = getSelectedTreeNodeValue("<%=QuestionFolderRadTreeView.ClientID %>"); console.log(treeId); var wbtAjaxArgs = 'ApplyQuestionFolder||' + treeId; var ajaxManager = $find("<%=PageRadAjaxManager.ClientID%>"); ajaxManager.ajaxRequest(wbtAjaxArgs); } var theForm = document.getElementById('wbtform'); function checkForm(pForm) { var bTest = true; if (bTest && isEmpty(pForm.<%=TxtName.ClientID%>)) { WbtRadAlert('<%=oLoc.GetStringJS("MsgCheckThemeName", oUser.Subdomain)%>', '', 300, 100); pForm.<%=TxtName.ClientID%>.focus(); bTest = false; } return bTest; } function onTabSelecting(sender, args) { var tabStrip = $find("<%= RadTabTheme.ClientID%>"); var tabInfo = tabStrip.findTabByValue('theme_info_tab'); var tabNext = args.get_tab().get_value(); var tmp = true; if (tabInfo.get_selected()) tmp = checkForm(theForm); if (!tmp) args.set_cancel(true); else if (<%=nThemeId%> == 0) { args.set_cancel(true); var wbtAjaxArgs = 'Create||' + theForm.<%=TxtName.ClientID%>.value + '||' + theForm.<%=TxtDescription.ClientID%>.value + '||' + tabNext; var ajaxManager = $find("<%= PageRadAjaxManager.ClientID%>"); console.log(wbtAjaxArgs); ajaxManager.ajaxRequest(wbtAjaxArgs); } } function selectTab(tabName) { var tabStrip = $find("<%= RadTabTheme.ClientID%>"); if (tabStrip) { var tab = tabStrip.findTabByValue(tabName); if (tab) tab.select(); } } function ThemeCreationError() { WbtRadAlert('<%=oLoc.GetStringJS("MsgThemeCreationError", oUser.Subdomain)%>', '', 300, 100); } </script> <asp:HiddenField ID="selected" runat="Server" /> <asp:HiddenField ID="dSelected" runat="Server" /> </telerik:RadScriptBlock> <telerik:RadWindowManager ID="PageRadWindowManager" runat="server" KeepInScreenBounds="true" VisibleStatusbar="false" VisibleTitlebar="false" Behaviors="Close" VisibleOnPageLoad="false"> <Windows> <telerik:RadWindow ID="PageRadWindow" runat="server" AutoSize="false" KeepInScreenBounds="true" VisibleStatusbar="false" VisibleTitlebar="true" Behaviors="Close,Move" Modal="true" VisibleOnPageLoad="false" /> </Windows> </telerik:RadWindowManager> <WBT:Header ID="header" runat="server" /> <!-- BEGIN CONTAINER --> <div class="page-container"> <WBT:Menu ID="menu" runat="server" /> <!-- BEGIN CONTENT --> <div class="page-content-wrapper"> <!-- BEGIN CONTENT BODY --> <div class="page-content"> <WBT:ContentHeader ID="contentheader" runat="server" /> <!-- BEGIN PAGE CONTENT --> <div class="row"> <div class="col-md-12"> <div class="portlet light portlet-fit"> <div class="portlet-body"> <div class="row"> <div class="col-md-2 col-xs-3"> <asp:UpdatePanel ID="tabs" runat="server" UpdateMode="Conditional"> <ContentTemplate> <telerik:RadTabStrip ID="RadTabTheme" runat="server" MultiPageID="RadMultiPageTheme" OnClientTabSelecting="onTabSelecting" Orientation="VerticalLeft" Width="100%" Skin="" SelectedIndex="0"> <Tabs> <telerik:RadTab runat="server" Value="theme_info_tab" TabIndex="0" PageViewID="theme_info_pv" CssClass="themeTab" SelectedCssClass="themeTabSelected" HoveredCssClass="themeTabHovered" DisabledCssClass="themeTabDisabled"></telerik:RadTab> <telerik:RadTab runat="server" Value="theme_questions_tab" TabIndex="1" PageViewID="theme_questions_pv" CssClass="themeTab" SelectedCssClass="themeTabSelected" HoveredCssClass="themeTabHovered" DisabledCssClass="themeTabDisabled"></telerik:RadTab> <telerik:RadTab runat="server" Value="theme_competence_tab" TabIndex="2" PageViewID="theme_competence_pv" CssClass="themeTab" SelectedCssClass="themeTabSelected" HoveredCssClass="themeTabHovered" DisabledCssClass="themeTabDisabled"></telerik:RadTab> </Tabs> </telerik:RadTabStrip> </ContentTemplate> </asp:UpdatePanel> </div> <div class="col-md-10 col-xs-9 " style="border-left: 2px solid #e7505a;"> <telerik:RadMultiPage ID="RadMultiPageTheme" runat="server" SelectedIndex="0"> <telerik:RadPageView runat="server" ID="theme_info_pv" TabIndex="0"> <div class="portlet-body form"> <form role="form"> <div class="form-body col-md-6"> <div class="form-group"> <label for="TxtName" id="LblName" runat="server">Name</label> <asp:TextBox ID="TxtName" runat="server" CssClass="form-control input-sm" placeholder="" MaxLength="50" /> </div> <div class="form-group"> <label for="TxtDescription" id="LblDescription" runat="server">Description</label> <asp:TextBox ID="TxtDescription" runat="server" CssClass="form-control input-sm" placeholder="" TextMode="MultiLine" MaxLength="255" /> </div> </div> </form> </div> </telerik:RadPageView> <telerik:RadPageView runat="server" ID="theme_questions_pv" TabIndex="1"> <div class="portlet-body form"> <form role="form"> <div class="form-body col-md-6"> <telerik:RadCodeBlock runat="server"> <div class="caption"><span class="caption-subject font-green bold uppercase"><%=oLoc.GetString("LblBoundQuestions", oUser.Subdomain)%></span></div> </telerik:RadCodeBlock> <div class="actions"> <a class="btn btn-circle btn-icon-only btn-default tooltips" data-toggle="modal" href="#responsive" data-container="body" data-placement="top" id="QuestionAdd" runat="server" onclick=""> <i class="fa fa-plus"></i> </a> <a class="btn btn-circle btn-icon-only btn-default tooltips" href="javascript:;" data-container="body" data-placement="top" id="QuestionDrop" runat="server" onclick="UnbindQuestions()"> <i class="fa fa-minus"></i> </a> </div> <asp:UpdatePanel runat="server" ID="QuestionsGridPanel" UpdateMode="Conditional"> <ContentTemplate> <telerik:RadGrid ID="QuestionsGrid" runat="server" Width="100%" AllowPaging="true" PageSize="10" ShowHeader="true" ShowFooter="false" ShowGroupPanel="false" ShowStatusBar="false" AutoGenerateColumns="false" OnNeedDataSource="QuestionsGrid_NeedDataSource" AllowMultiRowSelection="true" AllowAutomaticInserts="false" AllowAutomaticDeletes="false" AllowAutomaticUpdates="false" AllowSorting="true" AllowFilteringByColumn="true" BorderStyle="None" Style="overflow: auto;" HeaderStyle-Font-Bold="true" FilterType="HeaderContext"> <ClientSettings> <Scrolling AllowScroll="true" /> <Selecting AllowRowSelect="True" /> <ClientEvents OnRowSelected="QuestionsGrid_RowSelected" OnRowDeselected="QuestionsGrid_RowDeselected" /> </ClientSettings> <MasterTableView ClientDataKeyNames="ID"> <Columns> <telerik:GridClientSelectColumn UniqueName="CheckboxSelectQuestion" HeaderStyle-Width="5%" HeaderStyle-Wrap="false" ItemStyle-Wrap="false" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" ItemStyle-Width="5%" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" /> <telerik:GridBoundColumn UniqueName="QuestionId" HeaderText="" DataField="ID" Visible="false" AutoPostBackOnFilter="false" AllowFiltering="false" /> <telerik:GridBoundColumn UniqueName="QuestionTitle" HeaderText="Title" DataField="TITLE" HeaderStyle-Wrap="false" ItemStyle-Wrap="false" AutoPostBackOnFilter="false" AllowFiltering="false" /> </Columns> <PagerStyle AlwaysVisible="false" Mode="NumericPages" /> </MasterTableView> </telerik:RadGrid> </ContentTemplate> </asp:UpdatePanel> </div> </form> </div> </telerik:RadPageView> <telerik:RadPageView runat="server" ID="theme_competence_pv" TabIndex="2"> <div class="portlet-body form"> <form role="form"> <div class="form-body col-md-6"> </div> </form> </div> </telerik:RadPageView> </telerik:RadMultiPage> </div> </div> </div> </div> </div> </div> <div class="row"> <div class="col-md-10 col-xs-9 "> <div class="form-actions noborder"> <asp:Button ID="BtnCancel" runat="server" CssClass="btn otherAction" OnClick="BtnCancel_Click" /> <asp:Button ID="BtnSubmit" runat="server" CssClass="btn mainAction" OnClick="BtnSubmit_Click" OnClientClick="if(!checkForm(theForm))return (false);" /> </div> </div> </div> <!-- END PAGE CONTENT --> </div> <!-- END CONTENT BODY --> </div> <!-- BEGIN CONTENT --> </div> <!-- END CONTAINER --> <WBT:Footer ID="footer" runat="server" /> <!-- NEEDED FOR BINDING CONTROL --> <div id="responsive" class="modal fade" tabindex="-1" data-width="80%" data-height="80%" aria-hidden="true" style="display: none; width: 80%; margin-top: 0px;"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button> <h4 class="modal-title">Questions disponibles</h4> </div> <div class="modal-body"> <div class="row"> <div class="col-lg-4"> <telerik:RadTreeView ID="QuestionFolderRadTreeView" runat="server" OnClientNodeClicked="ApplyQuestionFolder" Style="white-space: normal; overflow: auto;" /> </div> <div class="col-lg-8"> <telerik:RadGrid ID="QuestionsGrid1" runat="server" Width="100%" AllowCustomPaging="True" AllowPaging="true" PageSize="10" ShowHeader="true" ShowFooter="false" ShowGroupPanel="false" ShowStatusBar="true" AutoGenerateColumns="false" OnNeedDataSource="QuestionsGrid1_NeedDataSource" AllowMultiRowSelection="true" AllowAutomaticInserts="false" AllowAutomaticDeletes="false" AllowAutomaticUpdates="false" AllowSorting="true" AllowFilteringByColumn="true" BorderStyle="None" GridLines="None" Style="overflow: auto; height: fill-available;" HeaderStyle-Font-Bold="true" DataKeyValues="ID"> <FilterMenu EnableEmbeddedBaseStylesheet="False" CssClass="dropdown-menu"></FilterMenu> <ClientSettings> <Scrolling AllowScroll="true" UseStaticHeaders="true" /> <Selecting AllowRowSelect="True" UseClientSelectColumnOnly="true" /> <ClientEvents OnRowSelected="QuestionsGrid1_RowSelected" OnRowDeselected="QuestionsGrid1_RowDeselected" /> </ClientSettings> <MasterTableView ClientDataKeyNames="ID"> <Columns> <telerik:GridClientSelectColumn UniqueName="CheckboxSelectQuestion" HeaderStyle-Width="5%" HeaderStyle-Wrap="false" ItemStyle-Wrap="false" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" ItemStyle-Width="5%" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"> </telerik:GridClientSelectColumn> <telerik:GridBoundColumn UniqueName="ID" HeaderText="Id" DataField="ID" AllowFiltering="true" HeaderStyle-Width="5%" ItemStyle-Width="5%" Visible="False"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn UniqueName="STATUS" HeaderStyle-Width="15%" ItemStyle-Width="15%" HeaderText="Status" DataField="STATUS" HeaderStyle-Wrap="false" ItemStyle-HorizontalAlign="Center"> <FilterTemplate> <asp:ImageButton Width="15px" ID="btnShowAll" OnClientClick="btnShowAll_Click()" runat="server" ImageUrl="../assets/global/plugins/mapplic/mapplic/images/error-icon.png" AlternateText="Clear filters" ToolTip="Clear filters" Style="vertical-align: middle;" /> <telerik:RadComboBox ID="RadComboBoxStatus" Style="width: 100px;" DataSourceID="SQLStatus" DataTextField="STATUS" DataValueField="STATUS" AppendDataBoundItems="true" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("STATUS").CurrentFilterValue %>' runat="server" OnClientLoad="RadComboBoxStatus_OnCliendLoadHandler" OnClientSelectedIndexChanged="StatusIndexChanged"> <Items> <telerik:RadComboBoxItem Text="All" /> </Items> </telerik:RadComboBox> <telerik:RadScriptBlock ID="RadScriptBlockStatus" runat="server"> <script type="text/javascript"> function RadComboBoxStatus_OnCliendLoadHandler(sender, args) { var rc = Telerik.Web.UI.RadComboBox.ComboBoxes[0]; var its = rc.get_items(); for (i = 1; i < its.get_count(); i++) { var it = its.getItem(i); it.set_text(" "); it.set_cssClass("glyphicon glyphicon-flag "+it.get_value().toLowerCase()+"_status"); } } function StatusIndexChanged(sender, args) { var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>"); tableView.filter("STATUS", args.get_item().get_value(), "EqualTo"); } </script> </telerik:RadScriptBlock> </FilterTemplate> <ItemTemplate> <span style="float: inherit !important;" class='glyphicon glyphicon-flag <%# DataBinder.Eval(Container.DataItem,"STATUS").ToString().ToLower() %>_status'></span> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridBoundColumn UniqueName="QuestionTitle" HeaderText="Title" DataField="TITLE" HeaderStyle-Wrap="false" ItemStyle-Wrap="false" AutoPostBackOnFilter="false" AllowFiltering="true" /> <telerik:GridBoundColumn UniqueName="TYPE" HeaderText="Type" HeaderStyle-Width="15%" ItemStyle-Width="15%" DataField="TYPE" HeaderStyle-Wrap="false" ItemStyle-Wrap="false" AutoPostBackOnFilter="false" AllowFiltering="true"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn UniqueName="QuestionReferenceLanguage" HeaderText="ReferenceLanguage" HeaderStyle-Width="15%" ItemStyle-Width="15%" DataField="REFERENCE_CULTURE" HeaderStyle-Wrap="false" ItemStyle-Wrap="false" AllowFiltering="true" AutoPostBackOnFilter="false"> <ItemTemplate><%# GetReferenceCulture(DataBinder.Eval(Container.DataItem,"REFERENCE_CULTURE").ToString(), DataBinder.Eval(Container.DataItem,"REFERENCE_STATUS").ToString().ToLower(), DataBinder.Eval(Container.DataItem,"TRANSLATION_STATUS").ToString().ToLower()) %></ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn UniqueName="QuestionCreationAdmin" HeaderText="Author" DataField="CREATION_ADMIN_ID" HeaderStyle-Wrap="false" ItemStyle-Wrap="false" AllowFiltering="true" AutoPostBackOnFilter="false"> <ItemTemplate><%# GetCreationAdmin(int.Parse(DataBinder.Eval(Container.DataItem,"CREATION_ADMIN_ID").ToString())) %></ItemTemplate> </telerik:GridTemplateColumn> </Columns> <PagerStyle AlwaysVisible="false" Mode="NumericPages" /> </MasterTableView> </telerik:RadGrid> </div> </div> </div> <div class="modal-footer"> <asp:Button type="button" runat="server" data-dismiss="modal" class="btn btn-outline dark" Text="Fermer" /> <asp:Button type="button" runat="server" data-dismiss="modal" OnClientClick="bindQuestions()" class="btn green" Text="Lier les questions" /> </div> </div> <asp:SqlDataSource ID="SQLStatus" ConnectionString="<%$ ConnectionStrings:XPERTeam %>" ProviderName="System.Data.SqlClient" SelectCommand="SELECT DISTINCT STATUS_ID as STATUS FROM QM_QUESTION" runat="server"></asp:SqlDataSource> <asp:SqlDataSource ID="SqlType" ConnectionString="<%$ ConnectionStrings:XPERTeam %>" ProviderName="System.Data.SqlClient" SelectCommand="SELECT DISTINCT QUESTION_TYPE_ID as TYPE FROM QM_QUESTION" runat="server"></asp:SqlDataSource> <!-- NEEDED FOR BINDING CONTROL --> <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel" runat="server" Transparency="30" MinDisplayTime="100" /> </form> <style> .rcbSlide { z-index: 20000 !important; } </style></body></html>
C#
using System;using System.Collections;using System.Collections.Generic;using System.Data;using System.Diagnostics;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Telerik.Web.UI;using XPTUtils;using XPTSocle;using WBTManagerObject.QM;namespace WBT.manageQuiz{ public partial class theme : System.Web.UI.Page { #region Variables protected string sCulture; protected Localization oLoc; public Users oUser = null; protected string sId = ""; protected string sParentId = ""; protected int nThemeId = 0; protected int nParentThemeId = 0; protected int nThemeFolderId = 0; protected Theme oTheme; protected int nNewThemeId = 0; protected string sTabToShow = ""; private DataSet QuestionsDS = null; protected DataSet questions_list = null; #endregion Variables protected void Page_Init(object sender, EventArgs e) { #region User if (Session["oUser"] != null) oUser = (Users)Session["oUser"]; else Response.Redirect("~/default.aspx"); #endregion User #region Localization sCulture = Request.Cookies["WBTCulturePref"].Value; oLoc = new Localization(sCulture); #endregion Localization #region Telerik PageSkinManager.Skin = oUser.Style.Tables["Styles"].Rows.Find(Domain_Styles.Telerik_Skin)["VALUE"].ToString(); #endregion Telerik #region Page controls settings contentheader.PageTitle = oLoc.GetString((Request["id"] != null) ? ("AltEditTheme") : ("AltAddTheme"), oUser.Subdomain); contentheader.SubDomain = oUser.Subdomain; contentheader.Localization = oLoc; #endregion Page controls settings #region Request params if (Request["parentid"] != null) { sParentId = Request["parentid"]; contentheader.CurrentObject = "parentid=" + sParentId; string[] tId = Request["parentid"].Split(":".ToCharArray(), StringSplitOptions.None); if (tId.Length > 2) int.TryParse(tId[2], out nParentThemeId); } if (Request["id"] != null) { int.TryParse(Request["id"], out nThemeId); } if (Request["tab"] != null) sTabToShow = Request["tab"]; #endregion Request params } protected void Page_Load(object sender, EventArgs e) { #region Session or ViewState // Theme Folder if (Session["oTheme"] != null) { oTheme = (Theme)Session["oTheme"]; Session["oTheme"] = null; } else if (ViewState["oTheme"] != null) oTheme = (Theme)ViewState["oTheme"]; else if (nThemeId > 0) oTheme = new Theme(nThemeId); #endregion Session or ViewState if (!IsPostBack) { #region Actions QuestionAdd.Attributes.Add("data-original-title", oLoc.GetString("AltAddQuestionsToTheme", oUser.Subdomain)); QuestionDrop.Attributes.Add("data-original-title", oLoc.GetString("AltDropQuestionsFromTheme", oUser.Subdomain)); #endregion Actions /* NEEDED FOR BINDING CONTROL */ #region treeview bool bTreeviewKeepExpanded = false; bool.TryParse(oUser.Setting.Tables["Settings"].Rows.Find(Domain_Settings.TreeviewKeepExpanded)["VALUE"].ToString(), out bTreeviewKeepExpanded); RadTreeNode myQuestionNode = new RadTreeNode(oLoc.GetString("LblQuestions", oUser.Subdomain), ""); myQuestionNode.Expanded = true; myQuestionNode.Selected = true; myQuestionNode.ExpandMode = TreeNodeExpandMode.ServerSideCallBack; QuestionFolderRadTreeView.Nodes.Add(myQuestionNode); QuestionFolderRadTreeView.SingleExpandPath = !bTreeviewKeepExpanded; QuestionFolder qf = new QuestionFolder(); BindSubQuestionFolderTreeView(myQuestionNode, qf.GetFolderChildrenDS("", false)); //QuestionFolderRadTreeView.ExpandAllNodes(); #endregion treeview #region Translation // Tab RadTabTheme.FindTabByValue("theme_info_tab").Text = oLoc.GetString("LblThemeInfo", oUser.Subdomain); RadTabTheme.FindTabByValue("theme_questions_tab").Text = oLoc.GetString("LblThemeQuestions", oUser.Subdomain); RadTabTheme.FindTabByValue("theme_competence_tab").Text = oLoc.GetString("LblThemeCompetency", oUser.Subdomain); // Buttons BtnSubmit.Text = oLoc.GetString("BtnSubmit", oUser.Subdomain); BtnCancel.Text = oLoc.GetString("BtnCancel", oUser.Subdomain); // Info Pageview LblName.InnerHtml = oLoc.GetString("LblThemeName", oUser.Subdomain); LblDescription.InnerHtml = oLoc.GetString("LblDescription", oUser.Subdomain); // MODAL // BtnBind.Text = oLoc.GetString("BtnBindQuestions", oUser.Subdomain); // BtnCloseBind.Text = oLoc.GetString("BtnCloseBind", oUser.Subdomain); #endregion Translation #region Fill values // Info Pageview if (oTheme != null) { TxtName.Text = oTheme.Name; TxtDescription.Text = oTheme.Description; } // Access Pageview #endregion Fill values #region Display correct tab after ajax. if (!string.IsNullOrWhiteSpace(sTabToShow) && oTheme != null) { string sUpdateScript = "setTimeout(\"selectTab('" + sTabToShow + "')\", 500);"; ScriptManager.RegisterStartupScript(Page, typeof(Page), "TabShow", sUpdateScript, true); int nIndex = 0; switch (sTabToShow) { case "theme_info_tab": nIndex = 0; break; case "theme_questions_tab": nIndex = 1; break; case "theme_competence_tab": nIndex = 2; break; } RadTabTheme.SelectedIndex = nIndex; RadMultiPageTheme.SelectedIndex = nIndex; } #endregion Display correct tab after ajax } #region Check user rights #endregion Check user rights } /* NEEDED FOR BINDING CONTROL */ /// <summary> /// Recursive method that adds nodes to a tree /// /// SIDE EFFECT : The childrenDS.Tables["Folders"].Rows are destroyed during the process /// /// </summary> /// <param name="parentNode">The node that needs children to be added</param> /// <param name="childrenDS">The children's DataSet of the folder being treated The table "Folders" is destroyed during the process</param> protected void BindSubQuestionFolderTreeView(RadTreeNode parentNode, DataSet childrenDS) { // Nodes are added only if the dataset of folders is not null nor empty if (childrenDS.Tables["Folders"].Rows != null && childrenDS.Tables["Folders"].Rows.Count > 0) { //Binding the current child to the parentNode DataRow child = childrenDS.Tables["Folders"].Rows[0]; RadTreeNode newNode = new RadTreeNode(child["NAME"].ToString(), child["FOLDER_ID"].ToString()); newNode.ExpandMode = TreeNodeExpandMode.ServerSideCallBack; parentNode.Nodes.Add(newNode); //Binding children of the current child int folder_id = 0; int.TryParse(child["FOLDER_ID"].ToString(), out folder_id); QuestionFolder qf = new QuestionFolder(folder_id); BindSubQuestionFolderTreeView(newNode, qf.GetFolderChildrenDS(folder_id.ToString(), false)); //Remove the current child childrenDS.Tables["Folders"].Rows.RemoveAt(0); //Process siblings of the current node BindSubQuestionFolderTreeView(parentNode, childrenDS); } } protected void Page_PreRender(object sender, EventArgs e) { if (oTheme != null) ViewState["oTheme"] = oTheme; } public void PageRadAjaxManager_AjaxRequest(object sender, AjaxRequestEventArgs e) { string argument = (e.Argument); string[] argumentArray = argument.Split("|".ToCharArray(), StringSplitOptions.None); if (e.Argument.StartsWith("Create")) OnThemeCreated(argumentArray[2], argumentArray[4], argumentArray[6]); /* NEEDED FOR BINDING CONTROL */ if (e.Argument.StartsWith("ClearFilters")) { btnShowAll_Click(); } if (e.Argument.StartsWith("ApplyQuestionFolder")) { int nQuestionFolderId = 0; int.TryParse(argumentArray[2], out nQuestionFolderId); QuestionsGrid1_update(nQuestionFolderId); } if (e.Argument.StartsWith("AddQuestionsTheme")) { Debug.WriteLine(QuestionsGrid.SelectedItems.Count); int nQuestionId = 0; for (int i = 2; i < argumentArray.Length - 1; i++) { int.TryParse(argumentArray[i], out nQuestionId); WBTManagerObject.QM.Theme.BindQuestionTheme(nThemeId,nQuestionId); } // tabs.Update(); QuestionsGrid_update(); //Response.Redirect(Request.RawUrl); } if (e.Argument.StartsWith("DropQuestionsTheme")) { int nQuestionId = 0; for (int i = 2; i < argumentArray.Length - 1; i++) { int.TryParse(argumentArray[i], out nQuestionId); WBTManagerObject.QM.Theme.DropQuestionTheme(nThemeId, nQuestionId); } // tabs.Update(); QuestionsGrid_update(); //Response.Redirect(Request.RawUrl); } } protected void QuestionsGrid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { QuestionsGrid.Columns.FindByUniqueName("QuestionTitle").HeaderText = oLoc.GetString("LblQuestionTitle", oUser.Subdomain); QuestionsGrid.MasterTableView.NoMasterRecordsText = oLoc.GetString("MsgQuestionThemeGridNoData", oUser.Subdomain); oTheme = new Theme(nThemeId); QuestionsDS = oTheme.GetQuestionsDS(nThemeId); QuestionsGrid.VirtualItemCount = QuestionsDS.Tables[0].Rows.Count; ; QuestionsGrid.DataSource = QuestionsDS; } public void QuestionsGrid_update() { { QuestionsGrid.Columns.FindByUniqueName("QuestionTitle").HeaderText = oLoc.GetString("LblQuestionTitle", oUser.Subdomain); QuestionsGrid.MasterTableView.NoMasterRecordsText = oLoc.GetString("MsgQuestionThemeGridNoData", oUser.Subdomain); oTheme = new Theme(nThemeId); QuestionsDS = oTheme.GetQuestionsDS(nThemeId); QuestionsGrid.VirtualItemCount = QuestionsDS.Tables[0].Rows.Count; ; QuestionsGrid.DataSource = QuestionsDS; QuestionsGrid.Rebind(); } } protected void QuestionsGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { QuestionsGrid1.Columns.FindByUniqueName("QuestionTitle").HeaderText = oLoc.GetString("LblQuestionTitle", oUser.Subdomain); QuestionsGrid1.Columns.FindByUniqueName("QuestionReferenceLanguage").HeaderText = oLoc.GetString("LblReferenceLanguage", oUser.Subdomain); QuestionsGrid1.MasterTableView.NoMasterRecordsText = oLoc.GetString("MsgQuestionThemeGridNoData", oUser.Subdomain); QuestionsGrid1.Columns.FindByUniqueName("TYPE").HeaderText = oLoc.GetString("LblQuestionType", oUser.Subdomain); QuestionsGrid1.Columns.FindByUniqueName("QuestionCreationAdmin").HeaderText = oLoc.GetString("LblCreationAdmin", oUser.Subdomain); QuestionFolder oQuestionFolder = new QuestionFolder(); QuestionsDS = oQuestionFolder.GetAllQuestionsDS(); QuestionsGrid1.VirtualItemCount = QuestionsDS.Tables[0].Rows.Count; var gd = QuestionsDS.Tables[0].Rows; Debug.WriteLine("QuestionsDS tables count : " + gd[2].ItemArray[2].ToString()); foreach (DataRow tr in QuestionsDS.Tables[0].Rows) { object[] tab = new object[tr.ItemArray.Length]; for (int i = 0; i < tr.ItemArray.Length; i++) { switch (tr.ItemArray[i].ToString()) { case "cm": tab[i] = oLoc.GetString("LblChoiceMultiple", oUser.Subdomain); break; case "DBQ": tab[i] = oLoc.GetString("LblDoubleQuestion", oUser.Subdomain); break; case "dragandrop": tab[i] = oLoc.GetString("LblDragAndDrop", oUser.Subdomain); break; case "essay": tab[i] = oLoc.GetString("LblEssay", oUser.Subdomain); break; case "FITB": tab[i] = oLoc.GetString("LblFillInTheBlank", oUser.Subdomain); break; case "hotspot": tab[i] = oLoc.GetString("LblHotspot", oUser.Subdomain); break; case "match": tab[i] = oLoc.GetString("LblMatch", oUser.Subdomain); break; case "matrix": tab[i] = oLoc.GetString("LblMatrix", oUser.Subdomain); break; case "order": tab[i] = oLoc.GetString("LblOrder", oUser.Subdomain); break; case "title": tab[i] = oLoc.GetString("LblTitle", oUser.Subdomain); break; default: tab[i] = tr.ItemArray[i]; break; } } tr.ItemArray = tab; } QuestionsGrid1.DataSource = QuestionsDS; questions_list = QuestionsDS; } /* NEEDED FOR BINDING CONTROL */ protected void QuestionsGrid1_update(int pQuestionFolderId) { QuestionFolder oQuestionFolder = new QuestionFolder(); QuestionsDS = pQuestionFolderId == 0 ? oQuestionFolder.GetAllQuestionsDS() : oQuestionFolder.GetElementsDS(pQuestionFolderId); QuestionsGrid1.VirtualItemCount = QuestionsDS.Tables[0].Rows.Count; QuestionsGrid1.DataSource = QuestionsDS; questions_list = QuestionsDS; QuestionsGrid1.Rebind(); } private void OnThemeCreated(string pName, string pDescription, string pNextTab) { oTheme = new Theme(); nNewThemeId = oTheme.Create(pName.Trim(), pDescription, nParentThemeId, oUser.User_Id, oUser.Domain_Id); if (nNewThemeId > 0) { if (!string.IsNullOrWhiteSpace(pDescription.Trim())) oTheme.Description = pDescription.Trim(); Session["oTheme"] = oTheme; Session["oQuestion"] = oTheme; QuestionFolder oThemeFolder = new QuestionFolder(nParentThemeId); Users_log.WriteLog(oUser.User_Id, oUser.Domain_Id, Users_log.Action.Add, Users_log.ObjType.QM_Question, nNewThemeId, "Successfully added theme " + pName.Trim() + " into folder" + oThemeFolder.Name); if (pNextTab != "") Response.Redirect("theme.aspx?id=" + oTheme.ThemeId + "&parentid=" + Request["parentid"].ToString() + "&tab=" + pNextTab); } else { oTheme.Fdelete = true; Users_log.WriteLog(oUser.User_Id, oUser.Domain_Id, Users_log.Action.Add, Users_log.ObjType.QM_Theme_Folder, 0, "Failed to Create theme " + pName.Trim()); ScriptManager.RegisterStartupScript(Page, typeof(Page), "ThemeCreationError", "ThemeCreationError()", true); } } protected void BtnCancel_Click(object sender, EventArgs e) { Response.Redirect("themes.aspx?id=" + ((nParentThemeId > 0) ? (nParentThemeId) : (0))); } protected void BtnSubmit_Click(object sender, EventArgs e) { UpdateData(); Response.Redirect("themes.aspx?id=" + ((nParentThemeId > 0) ? (nParentThemeId) : (0))); } protected void UpdateData() { if (oTheme != null) // Update theme folder { #region Update if (TxtName.Text.Trim() != oTheme.Name) { oTheme.Name = TxtName.Text.Trim(); Users_log.WriteLog(oUser.User_Id, oUser.Domain_Id, Users_log.Action.Edit, Users_log.ObjType.QM_Theme_Folder, oTheme.ThemeId, "Successfully edit theme name to " + oTheme.Name); } if (TxtDescription.Text.Trim() != (string.IsNullOrWhiteSpace(oTheme.Description) ? "" : oTheme.Description)) oTheme.Description = TxtDescription.Text; oTheme.Save(); #endregion Update } else // Create theme folder { #region Create oTheme = new Theme(); nNewThemeId = oTheme.Create(TxtName.Text.Trim(), TxtDescription.Text.Trim(), nParentThemeId, oUser.User_Id, oUser.Domain_Id); if (nNewThemeId > 0) { if (!string.IsNullOrWhiteSpace(TxtDescription.Text.Trim())) oTheme.Description = TxtDescription.Text.Trim(); Users_log.WriteLog(oUser.User_Id, oUser.Domain_Id, Users_log.Action.Add, Users_log.ObjType.QM_Theme_Folder, oTheme.ThemeId, "Successfully created theme " + oTheme.Name); } else Users_log.WriteLog(oUser.User_Id, oUser.Domain_Id, Users_log.Action.Add, Users_log.ObjType.QM_Theme_Folder, 0, "Failed to create theme " + TxtName.Text); #endregion Create } } //METHODS FOR THE MODAL public string GetCreationAdmin(int pCreationAdminId) { Users oUser = new Users(pCreationAdminId); return oUser.Fname + " " + oUser.Lname; } public string GetReferenceCulture(string pReferenceCulture, string pReferenceStatus, string pTranslationStatus) { string sReferenceCulture = QuizManagerObject.Utils.GetLblQuestionReferenceCulture(pReferenceCulture, oLoc, oUser.Subdomain); if (pReferenceStatus == "source") sReferenceCulture += "*"; else { if (pTranslationStatus == "translated") sReferenceCulture = "<font style=\"color:green\">" + sReferenceCulture + "</font>"; else if (pTranslationStatus == " nottranslated") sReferenceCulture = "<font style=\"color:red\">" + sReferenceCulture + "</font>"; else sReferenceCulture = "<font style=\"color:orange\">" + sReferenceCulture + "</font>"; } return sReferenceCulture; } //Show all = clear filters for QuestionsGrid1 (inside modal) !DEPRECATED! protected void btnShowAll_Click() { QuestionsGrid1.MasterTableView.FilterExpression = string.Empty; foreach (GridColumn column in QuestionsGrid1.MasterTableView.RenderColumns) { if (column is GridBoundColumn) { GridBoundColumn boundColumn = column as GridBoundColumn; boundColumn.CurrentFilterValue = string.Empty; } if (column is GridTemplateColumn) { GridTemplateColumn templateColumn = column as GridTemplateColumn; templateColumn.CurrentFilterValue = string.Empty; } } QuestionsGrid1.MasterTableView.Rebind(); } }}