This is a migrated thread and some comments may be shown as answers.

Dual listbox destination databound datatable not updating

2 Answers 74 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Revital
Top achievements
Rank 1
Revital asked on 29 Jun 2016, 12:47 PM

Hi,

I'm using Dual ListBox with the source and destination are databound to their respective datatables. After transfer to the right, the datatable is not updating and remains empty. I've tried both RadAjaxPanel and ASP UpdatePanel, the result is the same. 

Telerik Version: 

2014.1.403.45

ASPX:

001.<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
002.<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
003.<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
004.<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
005.<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
006.<%@ Import Namespace="Microsoft.SharePoint" %>
007.<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
008. 
009.<%@ Page Language="VB" AutoEventWireup="true" CodeBehind="PhoneBookPicker.aspx.vb" Inherits="XXXXXPortalAdditions.Layouts.XXXXXXPortalAdditions.Pages.PhoneBookPicker" DynamicMasterPageFile="~masterurl/default.master" %>
010. 
011.<%@ Register Assembly="Telerik.Web.UI, Version=2014.1.403.45, Culture=neutral, PublicKeyToken=121fae78165ba3d4" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
012. 
013.<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
014.</asp:Content>
015. 
016.<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
017. 
018.    <!--This is where we hide the not needed default SharePoint elements and fix margins -->
019.    <script type="text/javascript">
020.        $(document).ready(function () {
021. 
022.            $('#sideNavBox').css('display', 'none');
023.            $('#contentRow').css('padding-top', '0px');
024.            $('#contentBox').css({ 'margin-right': '0px', 'margin-left': '0px' })
025. 
026.        });
027.    </script>
028. 
029. 
030. 
031.    <input id="usrSearch" type="search" placeholder="חיפוש..." style="width: 154px; height: 25px; margin-bottom: 5px; margin-top: 2px; margin-right: 1px; background: url('/_layouts/15/images/XXXXXPortalAdditions/apps_search.png') no-repeat 6px 6px;" dir="rtl" />
032.    <div dir="ltr" style="margin-top: 40px; text-align: center;">
033. 
034.        <%-- <telerik:RadFormDecorator ID="RadFormDecorator1" DecoratedControls="All" runat="server" />
035.        <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">--%>
036.        <asp:UpdateProgress ID="updProgress" AssociatedUpdatePanelID="UpdatePanelAddFavs" runat="server">
037.            <ProgressTemplate>
038.                <div class="animationload">
039.                    <span>טוען...</span>
040.                    <div class="preloader"></div>
041.                </div>
042.            </ProgressTemplate>
043.        </asp:UpdateProgress>
044.        <asp:UpdatePanel runat="server" ID="UpdatePanelAddFavs" UpdateMode="Conditional" Visible="True">
045.            <ContentTemplate>
046. 
047.                <telerik:RadListBox ID="RadListBoxSource" runat="server" AllowTransfer="true" AllowAutomaticUpdates="True" AutoPostBackOnTransfer="true" AllowDelete="false" EnableDragAndDrop="true" SelectionMode="Multiple" ButtonSettings-ShowTransferAll="false" Localization-ToLeft="העבר חזרה לרשימה כללית" Localization-ToRight="העבר לקבוצת מועדפים שלי" Localization-MoveDown="הזז למטה" Localization-MoveUp="הזז למעלה" TransferToID="RadListBoxDestination" Height="400px" Width="300px"></telerik:RadListBox>
048. 
049.                <telerik:RadListBox ID="RadListBoxDestination" runat="server" AllowReorder="true" AllowAutomaticUpdates="True" AutoPostBackOnTransfer="true" EnableDragAndDrop="true" AllowDelete="false" SelectionMode="Multiple" Height="400px" Width="300px"></telerik:RadListBox>
050.                <div id="divButtons">
051.                    <asp:Button ID="btnSubmitFav" runat="server" Text="שמור שינויים" Height="40px" Width="80px" OnClick="btnSubmitFav_Click" />
052.                </div>
053.                <div id="divError" runat="server"></div>
054.                <%-- </telerik:RadAjaxPanel>--%>
055. 
056.            </ContentTemplate>
057.        </asp:UpdatePanel>
058.    </div>
059. 
060. 
061.    <!--This is where we filter the Listbox left side for XXXXX employees via keystrokes -->
062.    <!--I take the already existing class that the control adds to all the items and I work with it - class ".rlbItem" -->
063.    <script type="text/javascript">
064.        $(document).ready(
065.         function () {
066.             var $users = $('.rlbItem');
067.             $('#usrSearch').keyup(function () {
068.                 if ($.trim($(this).val()) == "") {
069.                     $users.show();
070.                     return;
071.                 }
072.                 var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
073. 
074.                 $users.show().filter(function () {
075.                     var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
076.                     return !~text.indexOf(val);
077.                 }).hide();
078.             });
079. 
080. 
081.         }
082.       );
083.    </script>
084.    <!--This is where we prevent default Enter key functionality -->
085.    <script type="text/javascript">
086.        $(document).ready(function () {
087.            $('.prvntEnterKey').bind('keypress', function (e) {
088.                if (e.keyCode == 13) {
089.                    e.preventDefault();
090. 
091.                }
092.            });
093.        });
094.    </script>
095.</asp:Content>
096. 
097.<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
098.</asp:Content>
099. 
100.<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server">
101.</asp:Content>

 

CodeBehind:

001.Imports System
002.Imports Microsoft.SharePoint
003.Imports Microsoft.SharePoint.WebControls
004.Imports MyDal
005.Imports System.Web.UI
006.Imports Telerik.Web.UI
007.Imports System.Text
008.Imports System.Web.UI.WebControls
009. 
010.Namespace Layouts.MyPortalAdditions.Pages
011. 
012.    Partial Public Class PhoneBookPicker
013.        Inherits LayoutsPageBase
014. 
015.#Region "Properties"
016.        'Private Property SrcTable() As DataTable
017.        '    Get
018.        '        Return CType(ViewState("SrcTable"), DataTable)
019.        '    End Get
020.        '    Set(ByVal value As DataTable)
021.        '        ViewState("SrcTable") = value
022.        '    End Set
023.        'End Property
024. 
025.        'Private Property DestTable() As DataTable
026.        '    Get
027.        '        Return CType(ViewState("DestTable"), DataTable)
028.        '    End Get
029.        '    Set(ByVal value As DataTable)
030.        '        ViewState("DestTable") = value
031.        '    End Set
032.        'End Property
033. 
034.        Private m_SrcTable As DataTable
035.        Public Property SrcTable() As DataTable
036.            Get
037.                Return m_SrcTable
038.            End Get
039.            Set(ByVal value As DataTable)
040.                m_SrcTable = value
041.            End Set
042.        End Property
043. 
044.        Private m_DestTable As DataTable
045.        Public Property DestTable() As DataTable
046.            Get
047.                Return m_DestTable
048.            End Get
049.            Set(ByVal value As DataTable)
050.                m_DestTable = value
051.            End Set
052.        End Property
053. 
054.        Private s_user As String
055.        Public Property sUser() As String
056.            Get
057.                Return s_user
058.            End Get
059.            Set(ByVal value As String)
060.                s_user = value
061.            End Set
062.        End Property
063.#End Region
064. 
065.#Region "Initializations"
066. 
067.        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
068. 
069.            If Not Page.IsPostBack Then
070.                initUser()
071.                initSrcTable()
072.                initDestTable()
073.                initRadListBoxSource()
074.                initRadListBoxDestination()
075.            End If
076. 
077.        End Sub
078. 
079.        Private Sub initUser()
080.            Dim oWeb As SPWeb = SPContext.Current.Web
081.            sUser = MyUtilities.GetCurrentUserLoginName(oWeb)
082.        End Sub
083. 
084.        Private Sub initSrcTable()
085.            Dim sMyDal As MyDal.SqlDal
086.            Dim connStr As String = ListsProvider.My_CONN_STR
087.            sMyDal = New SqlDal(connStr, True)
088.            Dim SPName As String = "PRS_MyData.dbo.USP_Get_EmployeePhone"
089.            Dim paramArr As SqlParams
090.            Try
091. 
092.                paramArr = New SqlParams
093.                paramArr.Add(New SqlParam("@SearchName", SqlParam.ParamType.ptChar, SqlParam.ParamDirection.pdInput, ""))
094.                SrcTable = sMyDal.ExecuteSPReturnDT(SPName, paramArr)
095. 
096.            Catch ex As Exception
097.                divError.Controls.Add(New LiteralControl("<div>Exception: " & ex.Message & "</div>"))
098.            Finally
099.                sMyDal = Nothing
100.            End Try
101. 
102.        End Sub
103. 
104.        Private Sub initDestTable()
105.            Dim sMyDal As MyDal.SqlDal
106.            Dim connStr As String = ListsProvider.My_CONN_STR
107.            sMyDal = New SqlDal(connStr, True)
108.            Dim SPName As String = "PRS_MyData.dbo.USP_PIE_GET_PERSONAL_LIST"
109.            Dim paramArr As SqlParams
110.            Try
111. 
112.                paramArr = New SqlParams
113.                paramArr.Add(New SqlParam("@AD_USER", SqlParam.ParamType.ptChar, SqlParam.ParamDirection.pdInput, sUser))
114.                DestTable = sMyDal.ExecuteSPReturnDT(SPName, paramArr)
115.                DestTable.AcceptChanges()
116. 
117.            Catch ex As Exception
118.                divError.Controls.Add(New LiteralControl("<div>Exception: " & ex.Message & "</div>"))
119.            Finally
120.                sMyDal = Nothing
121.            End Try
122.        End Sub
123. 
124.        Private Sub initRadListBoxSource()
125.            RadListBoxSource.DataSource = SrcTable
126.            RadListBoxSource.DataTextField = "Emp Name"
127.            RadListBoxSource.DataKeyField = "Employeeno"
128.            RadListBoxSource.DataBind()
129.        End Sub
130. 
131.        Private Sub initRadListBoxDestination()
132.            RadListBoxDestination.DataSource = DestTable
133.            RadListBoxDestination.DataTextField = "name"
134.            RadListBoxDestination.DataKeyField = "EMPNO"
135.            RadListBoxDestination.DataBind()
136.        End Sub
137. 
138.#End Region
139. 
140.#Region "DB Actions"
141. 
142.        Private Sub deleteFavoritesFromDB()
143.            Dim dt As DataTable
144.            Dim sMyDal As MyDal.SqlDal
145.            Dim connStr As String = ListsProvider.My_CONN_STR
146.            sMyDal = New SqlDal(connStr, True)
147.            Dim sSqlSelect As String = "Select * from PRS_MyData.dbo.Pie_Personal_List where AD_USER = '" & sUser & "'"
148.            Dim sSqlDelete As String = "Delete from PRS_MyData.dbo.Pie_Personal_List where AD_USER = '" & sUser & "'"
149.            Try
150.                dt = sMyDal.GetDataTable(sSqlSelect)
151.                If dt.Rows.Count > 0 Then
152.                    sMyDal.ExecuteSql(sSqlDelete)
153.                End If
154.            Catch ex As Exception
155.                divError.Controls.Add(New LiteralControl("<div>Exception: " & ex.Message & "</div>"))
156.            Finally
157.                sMyDal = Nothing
158.                dt = Nothing
159.            End Try
160.        End Sub
161. 
162.        Private Sub writeFavoritesToDB()
163.            Dim row As DataRow
164.            Dim sMyDal As MyDal.SqlDal
165.            Dim connStr As String = ListsProvider.My_CONN_STR
166.            sMyDal = New SqlDal(connStr, True)
167.            Dim SPname As String = "PRS_MyData.dbo.USP_PIE_ADD_PERSONAL_LIST_ITEM"
168.            Dim paramArr As SqlParams
169. 
170.            Try
171.                For Each row In DestTable.Rows
172.                    paramArr = New SqlParams
173.                    paramArr.Add(New SqlParam("@name", SqlParam.ParamType.ptChar, SqlParam.ParamDirection.pdInput, sUser))
174.                    paramArr.Add(New SqlParam("@EMPNO", SqlParam.ParamType.ptChar, SqlParam.ParamDirection.pdInput, row("empno").ToString()))
175.                    sMyDal.ExecuteSP(SPname, paramArr)
176.                Next
177. 
178.            Catch ex As Exception
179.                divError.Controls.Add(New LiteralControl("<div>Exception: " & ex.Message & "</div>"))
180.            Finally
181.                sMyDal = Nothing
182.            End Try
183.        End Sub
184. 
185.#End Region
186. 
187.#Region "Events"
188. 
189.        Protected Sub btnSubmitFav_Click(sender As Object, e As EventArgs)
190. 
191.            deleteFavoritesFromDB()
192.            If RadListBoxDestination.Items.Count > 0 Then
193.                writeFavoritesToDB()
194.            End If
195. 
196. 
197.        End Sub
198. 
199.#End Region
200. 
201. 
202.    End Class
203. 
204.End Namespace

Thanks in Advance!

2 Answers, 1 is accepted

Sort by
0
Revital
Top achievements
Rank 1
answered on 30 Jun 2016, 07:03 AM

[UPDATE]

Postback definitly occurs after each transfer. However, the Datatable is not populated with data...

0
Revital
Top achievements
Rank 1
answered on 30 Jun 2016, 01:30 PM

I decided to write my own solution from ground up. Including controls and everything.

Works like a charm... So, nevermind

Tags
ListBox
Asked by
Revital
Top achievements
Rank 1
Answers by
Revital
Top achievements
Rank 1
Share this question
or