Cannot transfer checkbx item in Listbox

6 posts, 0 answers
  1. Joe
    Joe avatar
    57 posts
    Member since:
    Mar 2013

    Posted 21 Jun 2013 Link to this post

    I had enabled checkbox feature in radlistbox,
    i had checked selected item in Source Listbox, but the transfer button still disable.
    i need to click either row in SourceListbox, and then the transfer button will be enable.

    how can i simply checked the checkbox and then click transfer button ? thanks

         <table>
               <tr>
     
    <td>
    Unselect
    <br />
    <telerik:RadListBox runat="server" ID="RadListBox_unselect" Height="200px" Width="230px"
        AllowTransfer="True" TransferToID="RadListBox_select"
             AutoPostBack="True" CheckBoxes="True"
            style="top: 0px; left: 0px" DataSourceID="ODS_Unselect"
            DataTextField="employee_display_name" DataValueField="employee_id" OnClientTransferring="clientTransfering">
     
    </telerik:RadListBox>
        <asp:ObjectDataSource ID="ODS_Unselect" runat="server"
            SelectMethod="GetEmployeeArrayByListByCourseID" TypeName="LRDB">
            <SelectParameters>
                <asp:SessionParameter DefaultValue="0" Name="id" SessionField="EmpList"
                    Type="String" />
            <asp:QueryStringParameter Name="CID" QueryStringField="CourseID"
                    Type="String" />
            </SelectParameters>
        </asp:ObjectDataSource>
                   </td>
    <td></td>
    <td>
    Selected
    <br />   
    <telerik:RadListBox runat="server" ID="RadListBox_select" Height="200px"
            Width="200px" TransferToID="RadListBox_unselect"
             AutoPostBack="True" CheckBoxes="True"              
            style="top: 0px; left: 0px">   
    </telerik:RadListBox>
        </td>
    </tr>
    </table>
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 24 Jun 2013 Link to this post

    Hi Joe,

    One suggestion is using javascript you can set the checked item as selected and hence the transfer button can be enabled on checking items. Please have a look at the sample code I tried which works as expected.

    ASPX:
    <telerik:RadListBox ID="RadListBox1" runat="server" Skin="Web20" AllowTransfer="true"
        CheckBoxes="true" OnClientItemChecked="OnClientItemChecked" SelectionMode="Multiple"
        TransferToID="RadListBox2">
        <Items>
            <telerik:RadListBoxItem runat="server" Text="ASP" />
            <telerik:RadListBoxItem runat="server" Text="WCF" />
            <telerik:RadListBoxItem runat="server" Text="WPF" />
        </Items>
    </telerik:RadListBox>
    <telerik:RadListBox ID="RadListBox2" runat="server" Skin="Web20">
        <Items>
            <telerik:RadListBoxItem runat="server" Text="JSP" />
            <telerik:RadListBoxItem runat="server" Text="JSF" />
        </Items>
    </telerik:RadListBox>

    JavaScript:
    <script type="text/javascript">
        function OnClientItemChecked(sender, args) {
            args.get_item().set_selected(true);
        }
    </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Joe
    Joe avatar
    57 posts
    Member since:
    Mar 2013

    Posted 24 Jun 2013 Link to this post

    thanks for your reply.

    i had implemented your code, but it still need to click either row to enable the transfer button.
    cannot just check the checkbox to enable the button.

    thanks
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 24 Jun 2013 Link to this post

    Hi Joe,

    Can you please provide your full code with the solution I provided?

    Thanks,
    Shinu.
  6. Joe
    Joe avatar
    57 posts
    Member since:
    Mar 2013

    Posted 24 Jun 2013 Link to this post

    <%@ Page Title="" Language="VB" MasterPageFile="~/LRDB.master" AutoEventWireup="false" CodeFile="training_session_create.aspx.vb" Inherits="training_session_create" %>
     
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
        <style type="text/css">
            .style4
            {
                text-decoration: underline;
            }
            .style10
            {
                width: 278px;
                height: 15px;
                background-color: #E7EEF6;
            }
            html .RadDropDownList_Default .rddlDisabled {
               border-color: #cccccc;
           }
            .style12
            {
                width: 278px;
                height: 32px;
                background-color: #E7EEF6;
            }
            .style13
            {
                height: 32px;
            }
            .style15
            {
                width: 96px;
            }
        </style>
     
        <script type="text/javascript">
     
            function clientTransfering(sender, args) {
                args.set_cancel(true);
                var checkedNodes = args.get_sourceListBox().get_checkedItems();
                for (var i in checkedNodes) {
                    var item = checkedNodes[i];
                    args.get_sourceListBox().transferToDestination(item);
     
                }
            }  
     
     
        function OnClientItemChecked(sender, args) {
            args.get_item().set_selected(true);
        }
     
        </script>
     
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
        <telerik:RadToolBar ID="rtbMenu" runat="server" Width="100%" Skin="Windows7">
            <Items>
                <telerik:RadToolBarButton Value="Save" Text="Save" Width="80px" Visible="true" />
                <telerik:RadToolBarButton IsSeparator="true" Visible="true" />
                <telerik:RadToolBarButton Value="Refresh" Text="Refresh" Width="80px" />
                <telerik:RadToolBarButton IsSeparator="true" />
                <telerik:RadToolBarButton Value="Back" Text="Back" Width="80px"  CausesValidation="false"/>
                <telerik:RadToolBarButton Value="BackSeparator" IsSeparator="true" />
            </Items>
        </telerik:RadToolBar>
                     <telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All" EnableRoundedCorners="true"   />
     
         <div class="div_menu"
               <div id="content_function" class="content_function">
     
                   <telerik:RadFormDecorator ID="RpFormDecorator" runat="server" Skin="Windows7"
                DecoratedControls="All" EnableRoundedCorners="true" />
                                  <div style="margin-left:5px;">
           <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
           <table style="width:80%;">
           <tr>
           <td align="left" valign="top" class="style10">Course
           </td>
           <td align="left" valign="top">
               <telerik:RadDropDownList ID="rdl_select_course" runat="server"
                   DefaultMessage="Please Select" AutoPostBack="True"
                   OnSelectedIndexChanged="rdl_select_course_OnSelectedIndexChanged"
                   DataSourceID="LDS_ddl_course" DataTextField="Course_Name"
                   DataValueField="Course_ID"   Enabled="false">
     
               </telerik:RadDropDownList>
               <asp:LinqDataSource ID="LDS_ddl_course" runat="server"
                   ContextTypeName="dcLRDBDataContext" EntityTypeName="" TableName="db_Courses">
               </asp:LinqDataSource>
               </td>
           </tr>
           <tr>
           <td align="left" valign="top" class="style10">Select Location
           </td>
           <td align="left" valign="top">
               <telerik:RadDropDownList ID="rdl_select_location" runat="server"
                   DefaultMessage="Please Select" Enabled="False" AutoPostBack="True"
                   OnSelectedIndexChanged="rdl_select_location_OnSelectedIndexChanged"
                   DataSourceID="LDS_ddl_location" DataTextField="Location"
                   DataValueField="Location_ID"  >
               </telerik:RadDropDownList>
               <asp:LinqDataSource ID="LDS_ddl_location" runat="server"
                   ContextTypeName="dcLRDBDataContext" EntityTypeName="" TableName="db_Locations">
               </asp:LinqDataSource>
               </td>
           </tr>
           <tr>
           <td align="left" valign="top" class="style10">Select Trainer
           </td>
           <td align="left" valign="top">
               <telerik:RadDropDownList ID="rdl_select_trainer" runat="server"
                   DefaultMessage="Please Select" Enabled="False" AutoPostBack="True"
                   OnSelectedIndexChanged="rdl_select_trainer_OnSelectedIndexChanged"
                   DataSourceID="ObjectDataSource1" DataTextField="DisplayName"
                   DataValueField="Trainer_ID" >
               </telerik:RadDropDownList> <asp:Label ID="errmsg_ddl_trainer" runat="server" Visible="false" Text="No available Trainer for this Course and Location"></asp:Label>
               <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
                   SelectMethod="GetTrainerDetailsArrayByUserID" TypeName="LRDB">
                   <SelectParameters>
                       <asp:SessionParameter Name="id" SessionField="AvailableTrainerID" Type="String" />
                   </SelectParameters>
               </asp:ObjectDataSource>
               </td>
           </tr>
           <tr>
           <td align="left" valign="top" class="style12">Selection Criteria
           </td>
           <td align="left" valign="top" class="style13">
      
     <table>
     <tr>
     <td class="style15">> Employee
     </td>
     <td>
         <telerik:RadDropDownTree ID="rdl_select_employee" runat="server"
             DataSourceID="ODS_Employee" DataTextField="employee_display_name"
             DataValueField="employee_id" DefaultMessage="Please Select" AutoPostBack="True"
             CheckBoxes="SingleCheck" Width="250px">
         </telerik:RadDropDownTree>
     
         <asp:ObjectDataSource ID="ODS_Employee" runat="server"
             SelectMethod="GetEmployeeDetailsArrayByCourseIDProjectID" TypeName="LRDB">
             <SelectParameters>
                  <asp:QueryStringParameter Name="CID" QueryStringField="CourseID" Type="Int32" />
                <asp:SessionParameter Name="PID" SessionField="SelectedPID" Type="Int32" />
             </SelectParameters>
         </asp:ObjectDataSource>
     
     </td>
     </tr>
     <tr>
     <td class="style15">> Role Type</td>
     <td>
         <telerik:RadDropDownTree ID="rdl_select_roletype" runat="server"
             DataSourceID="LDS_roletype" DataTextField="rolename"
             DataValueField="roletypeid" DefaultMessage="Please Select" AutoPostBack="True"
             CheckBoxes="SingleCheck" Width="250px">
         </telerik:RadDropDownTree>
         <asp:ObjectDataSource ID="ODS_roletype" runat="server"
             SelectMethod="GetRoleTypeByCourseIDProjectID" TypeName="LRDB">
             <SelectParameters>
                 <asp:QueryStringParameter Name="CID" QueryStringField="CourseID" Type="Int32" />
                 <asp:SessionParameter Name="PID" SessionField="SelectedPID" Type="Int32" />
             </SelectParameters>
         </asp:ObjectDataSource>
         <asp:LinqDataSource ID="LDS_roletype" runat="server"
             ContextTypeName="dcLRDBDataContext" EntityTypeName=""
             TableName="db_Dictionary_RoleTypes">
         </asp:LinqDataSource>
     
     </td>
     </tr>
     <tr>
     <td class="style15">> Job Title
     </td>
     <td>
         <telerik:RadDropDownTree ID="rdl_select_jobtitle" runat="server"
             DataSourceID="LDS_JobTitle" DataTextField="job_title"
             DataValueField="id" DefaultMessage="Please Select" AutoPostBack="True"
             CheckBoxes="SingleCheck" Width="250px">
         </telerik:RadDropDownTree>
         <asp:ObjectDataSource ID="ODS_JobTitle" runat="server"
             SelectMethod="GetJobTitleByCourseIDProjectID" TypeName="LRDB">
             <SelectParameters>
                 <asp:QueryStringParameter Name="CID" QueryStringField="CourseID" Type="Int32" />
                 <asp:SessionParameter Name="PID" SessionField="SelectedPID" Type="Int32" />
             </SelectParameters>
         </asp:ObjectDataSource>
                   <asp:LinqDataSource ID="LDS_JobTitle" runat="server"
             ContextTypeName="dcLRDBDataContext" EntityTypeName=""
             TableName="db_Dictionary_Job_Titles">
         </asp:LinqDataSource>
     </td>
     </tr>
     <tr>
     <td class="style15">> Department
     </td>
     <td>
         <telerik:RadDropDownTree ID="rdl_select_dept" runat="server"
             DataSourceID="LDS_Dept" DataTextField="department"
             DataValueField="deptid" DefaultMessage="Please Select" AutoPostBack="True"
             CheckBoxes="SingleCheck" Width="250px">
         </telerik:RadDropDownTree>
         <asp:ObjectDataSource ID="ODS_Dept" runat="server"
             SelectMethod="GetDeptByCourseIDProjectID" TypeName="LRDB">
             <SelectParameters>
                 <asp:QueryStringParameter Name="CID" QueryStringField="CourseID" Type="Int32" />
                 <asp:SessionParameter Name="PID" SessionField="SelectedPID" Type="Int32" />
             </SelectParameters>
         </asp:ObjectDataSource>
                        <asp:LinqDataSource ID="LDS_Dept" runat="server"
             ContextTypeName="dcLRDBDataContext" EntityTypeName=""
             TableName="db_Departments">
         </asp:LinqDataSource>
     </td>
     </tr>
     </table>
     
    <asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_click"/>
     
     
               <br />
               <br />
     
     
               <br />
               <br />
     
               <table>
                   <tr>
         
        <td>
        Unselect
        <br />
        <telerik:RadListBox runat="server" ID="RadListBox_unselect" Height="200px" Width="230px"
            AllowTransfer="True" TransferToID="RadListBox_select"
                 AutoPostBack="True" CheckBoxes="True" SelectionMode="Multiple"
                style="top: 0px; left: 0px" DataSourceID="ODS_Unselect" OnClientItemChecked="OnClientItemChecked"
                DataTextField="employee_display_name" DataValueField="employee_id" OnClientTransferring="clientTransfering">
     
        </telerik:RadListBox>
            <asp:ObjectDataSource ID="ODS_Unselect" runat="server"
                SelectMethod="GetEmployeeArrayByListByCourseID" TypeName="LRDB">
                <SelectParameters>
                    <asp:SessionParameter DefaultValue="0" Name="id" SessionField="EmpList"
                        Type="String" />
                <asp:QueryStringParameter Name="CID" QueryStringField="CourseID"
                        Type="String" />
                </SelectParameters>
            </asp:ObjectDataSource>
                       </td>
        <td></td>
        <td>
        Selected
        <br />   
        <telerik:RadListBox runat="server" ID="RadListBox_select" Height="200px"
                Width="200px" TransferToID="RadListBox_unselect"
                 AutoPostBack="True" CheckBoxes="True"              
                style="top: 0px; left: 0px">   
        </telerik:RadListBox>
            </td>
        </tr>
        </table>
                
     
               </td>
           </tr>
           <tr>
                
           <td align="left" valign="top" class="style10">Teaching Material URL
           </td>
           <td align="left" valign="top">
                
               <asp:TextBox ID="Tb_material_url" runat="server" Width="671px" Enabled="false"></asp:TextBox>
     
            </td>
            </tr>
           <tr>
                
           <td align="left" valign="top" class="style10">Attachment
           </td>
           <td align="left" valign="top">
                
     
                    <telerik:RadProgressManager runat="server" ID="RadProgressManager1" />
     
                        <telerik:RadAsyncUpload runat="server" ID="AsyncUpload_Attachment"
                        InitialFileInputsCount="1" MaxFileSize="10240000" MultipleFileSelection="Automatic" />
                          <telerik:RadProgressArea runat="server" ID="RadProgressArea1" />
                 
            </td>
            </tr>
           <tr>
           <td align="left" valign="top" class="style10">Select Date & Time
           </td>
           <td align="left" valign="top">
               <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" InitialDelayTime="200">
     
            </telerik:RadAjaxLoadingPanel>
                <telerik:RadScriptBlock runat="server" ID="RadScriptBlock1">
                       <script type="text/javascript">
     
            //<![CDATA[
     
                           var selectedAppointment = null;
                           var contextMenuSlot = null;
     
                           function checkResourceMenuItem(menu, appointment) {
                               var calendar = appointment.get_resources().getResourcesByType("Calendar").getResource(0);
                               if (!calendar)
                                   return;
     
                               var categorizeItem = menu.findItemByText("Categorize");
     
                               //Traverse all menu items below "Categorize"
                               for (var i = 0; i < categorizeItem.get_items().get_count(); i++) {
                                   var item = categorizeItem.get_items().getItem(i);
                                   if (item.get_value() == calendar.get_key()) {
     
                                       //The item corresponds to the current "Calendar" - the Value of the item stores the Key of the resource
                                       item.set_imageUrl("Images/checked.gif");
                                   }
                                   else {
                                       item.set_imageUrl("");
                                   }
                               }
                           }
     
                           //Called when the user right-clicks an appointment
                           function appointmentContextMenu(sender, eventArgs) {
                               var menu = $find("<%= SchedulerAppointmentContextMenu.ClientID %>");
                               selectedAppointment = eventArgs.get_appointment();
                               checkResourceMenuItem(menu, selectedAppointment);
                               menu.show(eventArgs.get_domEvent());
                           }
     
    //                       //Called when the user clicks an item from the appointment context menu
    //                       function appointmentContextMenuItemClicking(sender, eventArgs) {
    //                           var clickedItem = eventArgs.get_item();
     
    //                           if (clickedItem.get_text() == "Categorize") {
    //                               //Prevent the menu from closing if the user clicked the "Categorize" menu item
    //                               eventArgs.set_cancel(true);
    //                               return;
    //                           }
    //                       }
     
                           //Called when the user clicks an item from the appointment context menu
    //                       function appointmentContextMenuItemClicked(sender, eventArgs) {
    //                           if (!selectedAppointment)
    //                               return;
    //                           var clickedItem = eventArgs.get_item();
    //                           var scheduler = $find("<%= RadScheduler1.ClientID %>");
    //                           if (clickedItem.get_parent().get_text && clickedItem.get_parent().get_text() == "Categorize") {
    //                               //The user clicked the item corresponding to the "Calendar" resource to which the appointment is assigned
    //                               if (clickedItem.get_imageUrl())
    //                                   return;
    //                               //Clear all resources
    //                               selectedAppointment.get_resources().clear();
    //                               //Find the resource corresponding to the clicked item
    //                               var calendar = scheduler.get_resources().getResourceByTypeAndKey("Calendar", clickedItem.get_value());
    //                               //Add it to the appointment resources collection
    //                               selectedAppointment.get_resources().add(calendar);
    //                               //Update the appointment
    //                               scheduler.updateAppointment(selectedAppointment);
    //                           }
    //                       }              
               //]]>
     
            </script>
     
     
     
        </telerik:RadScriptBlock>
     
     
     
               <telerik:RadScheduler runat="server" ID="RadScheduler1" Width="748px"            
                Skin="Windows7" DataEndField="End_Time" DataKeyField="Session_ID"
                DataRecurrenceParentKeyField="RecurrenceParentId" DataRecurrenceField="RecurrenceRule"
                DataSourceID="LDS_schedule" DataStartField="Start_Time"
                OnAppointmentDelete="RadScheduler1_AppointmentDelete"
                OnAppointmentInsert="RadScheduler1_AppointmentInsert"
                OnAppointmentUpdate="RadScheduler1_AppointmentUpdate" OnAppointmentDataBound="RadScheduler1_DataBound"
                DataSubjectField="db_Course.Course_Name"    OnClientAppointmentContextMenu="appointmentContextMenu"          
                StartEditingInAdvancedForm="true" StartInsertingInAdvancedForm="false"                                  
                Enabled="false">
     
                <AdvancedForm Modal="true"></AdvancedForm>
                            <TimelineView UserSelectable="false"></TimelineView>
     
                <AppointmentContextMenus>
                    <%--The appointment context menu interaction is handled on the client in this example--%>
                    <%--See the JavaScript code above--%>
                    <telerik:RadSchedulerContextMenu runat="server" ID="SchedulerAppointmentContextMenu">
                        <Items>
                            <telerik:RadMenuItem Text="Open" Value="CommandEdit">
                            </telerik:RadMenuItem>
    <%--                        <telerik:RadMenuItem IsSeparator="True">
                            </telerik:RadMenuItem>
                            <telerik:RadMenuItem IsSeparator="True">
                            </telerik:RadMenuItem>--%>
                        </Items>
                    </telerik:RadSchedulerContextMenu>
                </AppointmentContextMenus>
            </telerik:RadScheduler>
                                                                        
                    <asp:LinqDataSource ID="LDS_schedule" runat="server"
                ContextTypeName="dcLRDBDataContext" EntityTypeName=""
                TableName="db_Training_Sessions"
                   Where="Project_ID == @Project_ID">
    <%--               Where="Course_ID == @Course_ID && Project_ID == @Project_ID">
    --%>
                        <WhereParameters>
                            <asp:QueryStringParameter Name="Course_ID" QueryStringField="CourseID"
                                Type="Int32" />
                            <asp:SessionParameter Name="Project_ID" SessionField="SelectedPID"
                                Type="Int32" />
                        </WhereParameters>
            </asp:LinqDataSource>
     
               </td>
           </tr>
     
           </table>
           </telerik:RadAjaxPanel>
     
           </div>
        
         </div>
         </div>
     
     
    </asp:Content>

    Code Behind

    Imports Telerik.Web.UI
     
    Partial Class training_session_create
        Inherits System.Web.UI.Page
        Dim CourseID As Integer
     
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not IsPostBack Then
                'Dim lb_panel As Label
                'lb_panel = CType(Master.FindControl("lb_panel"), Label)
                'lb_panel.Text = "Create Session"
                If Not IsNothing(Request.QueryString("CourseID")) Then
     
                    Session.Remove("SessionID")
                    Session.Remove("EmpList")
     
                    rdl_select_course.SelectedValue = Request.QueryString("CourseID").ToString
     
                    rdl_select_course.Enabled = False
                    rdl_select_location.Enabled = True
     
                    RadScheduler1.AllowDelete = False
                    RadScheduler1.AllowEdit = False
                    RadScheduler1.AllowInsert = False
     
                    'rdl_select_employee.Enabled = False
                    'rdl_select_dept.Enabled = False
                    'rdl_select_jobtitle.Enabled = False
                    'rdl_select_roletype.Enabled = False
     
                End If
     
            End If
        End Sub
        Protected Sub RadScheduler1_AppointmentInsert(ByVal sender As Object, ByVal e As AppointmentInsertEventArgs)
            Dim scheduler As RadScheduler = TryCast(sender, RadScheduler)
            'Dim room As Resource = e.Appointment.Resources.GetResourceByType("Room")
            'Dim roomId As System.Nullable(Of Integer) = If(room IsNot Nothing, CType(room.Key, System.Nullable(Of Integer)), Nothing)
            Dim dc As New dcLRDBDataContext
            Dim SessionID As System.Nullable(Of Short) = 0
            Dim sid As Integer = 0
     
            'Check if there any row/record create
            If IsNothing(HttpContext.Current.Session("SessionID")) Then
                Dim dc1 As New dcLRDBDataContext
                Dim newRecord1 As New db_Training_Session
     
                dc1.db_Training_Sessions.InsertOnSubmit(newRecord1)
                newRecord1.Project_ID = Session("SelectedPID").ToString
                newRecord1.Course_ID = Request.QueryString("CourseID").ToString
                newRecord1.LastUpdateDate = DateTime.Now
                newRecord1.LastUpdateBy = HttpContext.Current.Session("UserID")
                'newRecord1.status = "Temp"
                dc1.SubmitChanges()
                sid = newRecord1.Session_ID
                dc1.Dispose()
                HttpContext.Current.Session("SessionID") = sid
            End If
     
            dc.insertSession(SessionID, HttpContext.Current.Session("SessionID"), Session("SelectedPID").ToString, Request.QueryString("CourseID").ToString, rdl_select_trainer.SelectedValue, rdl_select_location.SelectedValue, "", e.Appointment.Start, e.Appointment.[End], e.Appointment.RecurrenceRule, CType(e.Appointment.RecurrenceParentID, System.Nullable(Of Integer)), DateTime.Now, HttpContext.Current.Session("UserID"))
     
            If SessionID.HasValue Then
                'lb_test.Text = "Inserted Value --> " & Convert.ToString(SessionID)
            Else
                'lb_test.Text = "No Value .."
            End If
     
            RadScheduler1.DataBind()
     
        End Sub
        Protected Sub RadScheduler1_AppointmentUpdate(ByVal sender As Object, ByVal e As AppointmentUpdateEventArgs)
            Dim scheduler As RadScheduler = TryCast(sender, RadScheduler)
            'Dim room As Resource = e.ModifiedAppointment.Resources.GetResourceByType("Room")
            'Dim roomId As System.Nullable(Of Integer) = If(room IsNot Nothing, CType(room.Key, System.Nullable(Of Integer)), Nothing)
            Dim dc As New dcLRDBDataContext
     
            dc.updateSession(Convert.ToInt32(e.Appointment.ID), Session("SelectedPID").ToString, Request.QueryString("CourseID").ToString, rdl_select_trainer.SelectedValue, rdl_select_location.SelectedValue, "Draft", e.ModifiedAppointment.Start, e.ModifiedAppointment.[End], e.ModifiedAppointment.RecurrenceRule, _
            CType(e.ModifiedAppointment.RecurrenceParentID, System.Nullable(Of Integer)), DateTime.Now, HttpContext.Current.Session("UserID"))
            RadScheduler1.DataBind()
     
        End Sub
     
        Protected Sub RadScheduler1_AppointmentDelete(ByVal sender As Object, ByVal e As SchedulerCancelEventArgs)
            Dim scheduler As RadScheduler = TryCast(sender, RadScheduler)
            Dim dc As New dcLRDBDataContext
            Dim appt_id As Integer = 0
            appt_id = Convert.ToInt32(e.Appointment.ID)
     
            Dim i As Integer
     
     
     
            If Not IsNothing(HttpContext.Current.Session("SessionID")) Then
                Dim res = (From a In dc.db_Training_Sessions Where a.Session_ID = appt_id).ToList
                For i = 0 To res.Count - 1
                    If res.Item(i).Parent_ID = HttpContext.Current.Session("SessionID").ToString Then
                        dc.deleteSession(Convert.ToInt32(e.Appointment.ID))
                        RadScheduler1.DataBind()
                    Else
                        Page.ClientScript.RegisterStartupScript(Page.GetType(), "MessageBox", "alert('You cannot delete time slot belongs to other session.');", True)
                    End If
     
                Next
            Else
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "MessageBox", "alert('You cannot delete time slot belongs to other session.');", True)
            End If
     
        End Sub
     
        Protected Sub rtbMenu_ButtonClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadToolBarEventArgs) Handles rtbMenu.ButtonClick
     
            If e.Item.Value = "Save" Then
                UpdateValues()
                'Response.Redirect("~/TrainingAdmin/training_session_create.aspx?CourseID=" & Request.QueryString("CourseID"))
                Session.Remove("SessionID")
                Response.Redirect("~/TrainingAdmin/training_session.aspx?CourseID=" & Request.QueryString("CourseID"))
            ElseIf e.Item.Value = "Refresh" Then
                If HttpContext.Current.Session("SessionID") IsNot Nothing Then
                    ClearValues()
                End If
                Session.Remove("SessionID")
                If Not IsNothing(Request.QueryString("CourseID")) Then
                    Response.Redirect("~/TrainingAdmin/training_session_create.aspx?CourseID=" & Request.QueryString("CourseID"))
                Else
                    Response.Redirect("~/TrainingAdmin/training_session_create.aspx")
                End If
            ElseIf e.Item.Value = "Back" Then
                If HttpContext.Current.Session("SessionID") IsNot Nothing Then
                    ClearValues()
                End If
                Session.Remove("SessionID")
                Response.Redirect("~/TrainingAdmin/training_session.aspx?CourseID=" & Request.QueryString("CourseID"))
            ElseIf e.Item.Value = "Home" Then
                Session.Remove("SessionID")
                Response.Redirect("~/TrainingAdmin/training_course.aspx")
            End If
        End Sub
     
        Protected Sub rdl_select_course_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdl_select_course.SelectedIndexChanged
            If rdl_select_course.SelectedText <> rdl_select_course.DefaultMessage And rdl_select_course.SelectedText <> "" And rdl_select_location.Enabled = False Then
                'rdl_select_location.ClearSelection()
                'rdl_select_location.BorderWidth = "1"
                'rdl_select_location.BorderColor = Drawing.Color.OrangeRed
                rdl_select_location.Enabled = True
            End If
            If rdl_select_course.SelectedText <> "" And rdl_select_location.SelectedText <> "" Then
                CheckValid("Course")
            End If
        End Sub
     
        Protected Sub rdl_select_location_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdl_select_location.SelectedIndexChanged
            If rdl_select_location.SelectedText <> rdl_select_location.DefaultMessage And rdl_select_trainer.Enabled = False Then
                'rdl_select_location.BorderWidth = "0"
                'rdl_select_trainer.BorderWidth = "1"
                rdl_select_trainer.Enabled = True
                'rdl_select_trainer.BorderColor = Drawing.Color.OrangeRed
            End If
            CheckValid("Location")
     
        End Sub
     
        Protected Sub rdl_select_trainer_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdl_select_trainer.SelectedIndexChanged
            'If rdl_select_trainer.SelectedText <> rdl_select_trainer.DefaultMessage And rdl_select_employee.Enabled = False Then
            If rdl_select_trainer.SelectedText <> rdl_select_trainer.DefaultMessage Then
                'rdl_select_trainer.BorderWidth = "0"
                'rdl_select_employee.BorderWidth = "1"
                'rdl_select_employee.Enabled = True
                'rdl_select_employee.BorderColor = Drawing.Color.OrangeRed
     
                Tb_material_url.Enabled = True
     
                RadScheduler1.Enabled = True
                RadScheduler1.AllowDelete = True
                RadScheduler1.AllowEdit = True
                RadScheduler1.AllowInsert = True
     
                'RadListBoxDestination_Dept.Enabled = True
                'RadListBoxDestination_Employee.Enabled = True
                'RadListBoxDestination_RoleType.Enabled = True
                'RadListBoxDestination_job_title.Enabled = True
                'RadListBoxSource_Dept.Enabled = True
                'RadListBoxSource_Employee.Enabled = True
                'RadListBoxSource_RoleType.Enabled = True
                'RadListBoxSource_job_title.Enabled = True
            End If
        End Sub
     
        'Protected Sub rdl_select_employee_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdl_select_employee.SelectedIndexChanged
        '    ''If rdl_select_employee.SelectedText <> rdl_select_employee.DefaultMessage And RadListBoxSource_Employee.Enabled = False And RadListBoxDestination_employee.Enabled = False Then
        '    'If rdl_select_employee.SelectedText <> rdl_select_employee.DefaultMessage Then
        '    '    'rdl_select_employee.BorderWidth = "0"           
        '    '    RadListBoxSource_Employee.Enabled = True
        '    '    RadListBoxSource_RoleType.Enabled = True
        '    '    RadListBoxSource_Dept.Enabled = True
        '    '    RadListBoxDestination_Employee.Enabled = True
        '    '    RadListBoxDestination_Dept.Enabled = True
        '    '    RadListBoxDestination_RoleType.Enabled = True
        '    '    'RadScheduler1.Enabled = True
        '    'End If
     
        '    'If rdl_select_employee.SelectedValue = "Employee" Then
        '    '    'Panel_Employee.Visible = True
        '    '    'Panel_Dept.Visible = False
        '    '    'Panel_RoleType.Visible = False
        '    '    RadListBoxDestination_Employee.DataBind()
        '    '    RadListBoxSource_Employee.DataBind()
        '    'ElseIf rdl_select_employee.SelectedValue = "RoleType" Then
        '    '    'Panel_Employee.Visible = False
        '    '    'Panel_Dept.Visible = False
        '    '    'Panel_RoleType.Visible = True
        '    '    RadListBoxDestination_RoleType.DataBind()
        '    '    RadListBoxSource_RoleType.DataBind()
        '    'ElseIf rdl_select_employee.SelectedValue = "Dept" Then
        '    '    'Panel_Employee.Visible = False
        '    '    'Panel_Dept.Visible = True
        '    '    'Panel_RoleType.Visible = False
        '    '    RadListBoxDestination_Dept.DataBind()
        '    '    RadListBoxSource_Dept.DataBind()
        '    'End If
     
        'End Sub
     
        Protected Sub CheckValid(ByVal ddl As String)
            Dim TID As String = ""
     
            If (ddl = "Location") Or (ddl = "Course") Then
                TID = GetAvailableTrainerIDByLocationIDCourseID(rdl_select_location.SelectedValue, rdl_select_course.SelectedValue)
                HttpContext.Current.Session("AvailableTrainerID") = TID
                If TID <> "" Then
                    errmsg_ddl_trainer.Visible = False
                    rdl_select_course.BorderWidth = "0"
                    rdl_select_location.BorderWidth = "0"
     
                    If (ddl = "Course") Then
                        rdl_select_location.ClearSelection()
                        rdl_select_location.SelectedText = rdl_select_trainer.DefaultMessage
                        rdl_select_location.DataBind()
     
                        'RadListBoxSource_Employee.Enabled = True
                        'RadListBoxDestination_Employee.Enabled = True
                        'RadListBoxSource_Dept.Enabled = True
                        'RadListBoxDestination_Dept.Enabled = True
                        'RadListBoxSource_RoleType.Enabled = True
                        'RadListBoxDestination_RoleType.Enabled = True
                        'RadListBoxSource_job_title.Enabled = True
                        'RadListBoxDestination_job_title.Enabled = True
                        RadScheduler1.Enabled = True
     
                    End If
     
                    rdl_select_trainer.ClearSelection()
                    rdl_select_trainer.SelectedText = rdl_select_trainer.DefaultMessage
                    rdl_select_trainer.DataBind()
     
                    'RadListBoxDestination_Employee.DataBind()
                    'RadListBoxSource_Employee.DataBind()
                    'RadListBoxDestination_RoleType.DataBind()
                    'RadListBoxSource_RoleType.DataBind()
                    'RadListBoxDestination_Dept.DataBind()
                    'RadListBoxSource_Dept.DataBind()
                    'RadListBoxDestination_job_title.DataBind()
                    'RadListBoxSource_job_title.DataBind()
     
                Else
                    rdl_select_trainer.Enabled = False
                    Tb_material_url.Enabled = False
     
                    rdl_select_trainer.ClearSelection()
                    'rdl_select_employee.BorderWidth = "0"
                    rdl_select_course.BorderWidth = "1"
                    rdl_select_course.BorderColor = Drawing.Color.OrangeRed
                    rdl_select_location.BorderWidth = "1"
                    rdl_select_location.BorderColor = Drawing.Color.OrangeRed
                    errmsg_ddl_trainer.Visible = True
     
                    'rdl_select_employee.ClearSelection()
                    'rdl_select_employee.Enabled = False
                    'RadListBoxSource_Employee.Enabled = False
                    'RadListBoxDestination_Employee.Enabled = False
                    'RadListBoxSource_Dept.Enabled = False
                    'RadListBoxDestination_Dept.Enabled = False
                    'RadListBoxSource_RoleType.Enabled = False
                    'RadListBoxDestination_RoleType.Enabled = False
                    'RadListBoxSource_job_title.Enabled = False
                    'RadListBoxDestination_job_title.Enabled = False
                    RadScheduler1.Enabled = False
                End If
            End If
        End Sub
     
        Protected Sub UpdateValues()
     
            'Check if there any row/record create
            Dim SessionID As System.Nullable(Of Short) = 0
            Dim sid As Integer = 0
            If IsNothing(HttpContext.Current.Session("SessionID")) Then
                Dim dc3 As New dcLRDBDataContext
                Dim newRecord3 As New db_Training_Session
     
                dc3.db_Training_Sessions.InsertOnSubmit(newRecord3)
                newRecord3.Project_ID = Session("SelectedPID").ToString
                newRecord3.Course_ID = Request.QueryString("CourseID").ToString
                newRecord3.LastUpdateDate = DateTime.Now
                newRecord3.LastUpdateBy = HttpContext.Current.Session("UserID")
                dc3.SubmitChanges()
                sid = newRecord3.Session_ID
                dc3.Dispose()
                HttpContext.Current.Session("SessionID") = sid
            End If
     
            Dim dc1 As New dcLRDBDataContext
            Dim start_time As System.Nullable(Of DateTime) = Nothing
            Dim end_time As System.Nullable(Of DateTime) = Nothing
            Dim rec1 = (From p In dc1.db_Training_Sessions Where p.Parent_ID = HttpContext.Current.Session("SessionID").ToString Order By p.Start_Time).FirstOrDefault
            If Not rec1 Is Nothing Then
                If Not IsNothing(rec1.Start_Time) Then
                    start_time = rec1.Start_Time
                End If
                If Not IsNothing(rec1.End_Time) Then
                    end_time = rec1.End_Time
                End If
            End If
     
            Dim dc As New dcLRDBDataContext
            Dim rec = (From p In dc.db_Training_Sessions Where p.Session_ID = HttpContext.Current.Session("SessionID").ToString).FirstOrDefault
            If Not rec Is Nothing Then
                rec.Location_ID = rdl_select_location.SelectedValue
                rec.Trainer_ID = rdl_select_trainer.SelectedValue
                rec.status = "Draft"
                rec.LastUpdateDate = DateTime.Now
                rec.LastUpdateBy = HttpContext.Current.Session("UserID")
                If Tb_material_url.Text <> "" Then
                    rec.MaterialURL = Tb_material_url.Text.Trim
                End If
     
                If Not IsNothing(start_time) Then
                    rec.Date = start_time
                    rec.Start_Time = start_time
                End If
                dc.SubmitChanges()
            End If
     
            Using db As New dcLRDBDataContext
                Dim rec2 = From p In db.db_Training_Sessions Where p.Parent_ID = HttpContext.Current.Session("SessionID").ToString
                For Each p2 In rec2
                    p2.Location_ID = rdl_select_location.SelectedValue
                    p2.Trainer_ID = rdl_select_trainer.SelectedValue
                    p2.status = "Draft"
                    If Tb_material_url.Text <> "" Then
                        p2.MaterialURL = Tb_material_url.Text.Trim
                    End If
                    p2.LastUpdateDate = DateTime.Now
                    p2.LastUpdateBy = HttpContext.Current.Session("UserID")
                Next
                db.SubmitChanges()
            End Using
     
            dc.Dispose()
     
            ''Insert list box selected value to db
            Dim dc2 As New dcLRDBDataContext
            Dim i As Integer
     
            For i = 0 To RadListBox_select.Items.Count - 1
                dc2.insertSessionDetails_Employee(Session("SessionID").ToString, RadListBox_select.Items(i).Value.ToString, DateTime.Now, HttpContext.Current.Session("UserID"))
            Next
     
        End Sub
     
        Protected Sub ClearValues()
            Dim dc As New dcLRDBDataContext
            Dim result = (From cs In dc.db_Training_Sessions Where cs.Parent_ID = Session("SessionID").ToString And (cs.status Is Nothing Or cs.status = "") Select cs.Session_ID).ToList
            Dim i As Integer
     
            If Not IsNothing(result) Then
                For i = 0 To result.Count - 1
                    dc.deleteSession(result.Item(i).ToString)
                Next
            End If
     
            dc.deleteSession(Session("SessionID").ToString)
     
        End Sub
     
        Protected Sub btnSearch_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
            Dim list_employee As String
            Dim list_roletype As String
            Dim list_dept As String
            Dim list_jobtitle As String
     
            Dim rList As String = ""
            Dim emp_list As String = ""
     
            If rdl_select_employee.SelectedText <> rdl_select_employee.DefaultMessage Then
                list_employee = rdl_select_employee.SelectedValue
                rList = GetEmployeeListByListByType(list_employee, "Employee")
            End If
     
            If rList <> String.Empty Then
                emp_list = rList & ","
            End If
     
            If rdl_select_roletype.SelectedText <> rdl_select_roletype.DefaultMessage Then
                list_roletype = rdl_select_roletype.SelectedValue
                rList = GetEmployeeListByListByType(list_roletype, "RoleType")
            End If
     
            If rList <> String.Empty Then
                emp_list += rList & ","
            End If
     
            If rdl_select_dept.SelectedText <> rdl_select_dept.DefaultMessage Then
                list_dept = rdl_select_dept.SelectedValue
                rList = GetEmployeeListByListByType(list_dept, "Dept")
            End If
     
            If rList <> String.Empty Then
                emp_list += rList & ","
            End If
     
            If rdl_select_jobtitle.SelectedText <> rdl_select_jobtitle.DefaultMessage Then
                list_jobtitle = rdl_select_jobtitle.SelectedValue
                rList = GetEmployeeListByListByType(list_jobtitle, "JobTitle")
            End If
     
            If rList <> String.Empty Then
                emp_list += rList
            End If
     
            emp_list = TrimList(emp_list)
     
            Dim eList = Split(emp_list, ",")
            Dim b As New List(Of String)()
            b.AddRange(eList.Distinct())
            b.Sort()
     
            Dim tmp As String = ""
     
            For Each x In b
                tmp += x & ","
            Next
     
            tmp = TrimList(tmp)
     
            HttpContext.Current.Session("EmpList") = tmp
            RadListBox_unselect.DataBind()
     
        End Sub
     
        Protected Sub RadScheduler1_DataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.SchedulerEventArgs)
            If Not e.Appointment.ID Is Nothing Then
                'Same Course
                If GetCourseIDBySessionID(e.Appointment.ID).ToString = Request.QueryString("CourseID").ToString Then
     
                    e.Appointment.BackColor = Drawing.Color.LightBlue
     
                Else    'Another course
                    e.Appointment.BackColor = Drawing.Color.YellowGreen
                End If
     
                e.Appointment.AllowDelete = False
                e.Appointment.AllowEdit = False
     
                If Not IsNothing(HttpContext.Current.Session("SessionID")) Then
                    If e.Appointment.ID.ToString = HttpContext.Current.Session("SessionID").ToString Then
                        e.Appointment.AllowDelete = True
                        e.Appointment.AllowEdit = True
                    End If
                End If
     
            End If
     
        End Sub
    End Class
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Jun 2013 Link to this post

    Hi Joe,

    Unfortunately I couldn't replicate the issue and your code is working fine at my end.

    Thanks,
    Shinu.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017