Hello,
I'm using two listboxes inside of a tooltip. The list boxes are configured for single transfer with drag and drop enabled. I am having a problem where I am unable to transfer a single item between the listboxes. Any ideas why this might be happening? I'm using VS2010 and the .NET 4 version of the latest build of Telerik.
Thanks in advance.
Larry
I'm using two listboxes inside of a tooltip. The list boxes are configured for single transfer with drag and drop enabled. I am having a problem where I am unable to transfer a single item between the listboxes. Any ideas why this might be happening? I'm using VS2010 and the .NET 4 version of the latest build of Telerik.
Customer.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="customers.aspx.cs" Inherits="customers" %>
<%@ Register Src="assignusers.ascx" TagName="ProductDetails" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
asp:ScriptManager
ID
=
"ScriptManager1"
runat
=
"server"
/>
<
telerik:RadAjaxLoadingPanel
ID
=
"LoadingPanel1"
runat
=
"server"
Skin
=
"Windows7"
/>
<
telerik:RadAjaxManager
ID
=
"AjaxManager1"
runat
=
"server"
EnablePageHeadUpdate
=
"false"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGrid1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"Literal1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadToolTipManager1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
telerik:RadToolTipManager
ID
=
"RadToolTipManager1"
OffsetY
=
"-1"
HideEvent
=
"ManualClose"
Width
=
"620"
Height
=
"230"
runat
=
"server"
EnableShadow
=
"true"
OnAjaxUpdate
=
"OnAjaxUpdate"
RelativeTo
=
"Element"
Position
=
"MiddleRight"
Modal
=
"true"
>
</
telerik:RadToolTipManager
>
<
asp:Literal
ID
=
"Literal1"
runat
=
"server"
Text
=
""
/>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AutoGenerateColumns
=
"false"
DataSourceID
=
"EntityDataSource1"
AllowAutomaticInserts
=
"true"
AllowAutomaticUpdates
=
"true"
AllowAutomaticDeletes
=
"true"
AllowPaging
=
"true"
PageSize
=
"10"
EnableLinqExpressions
=
"false"
OnItemCommand
=
"RadGrid1_ItemCommand"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
>
<
MasterTableView
DataKeyNames
=
"id"
CommandItemDisplay
=
"Top"
EditMode
=
"PopUp"
>
<
EditFormSettings
CaptionFormatString
=
"Add/Edit Customers"
PopUpSettings-Modal
=
"true"
EditFormType
=
"WebUserControl"
UserControlName
=
"editcustomer.ascx"
PopUpSettings-Width
=
"700px"
>
</
EditFormSettings
>
<
Columns
>
<
telerik:GridButtonColumn
ButtonType
=
"LinkButton"
Text
=
"edit"
CommandName
=
"Edit"
/>
<
telerik:GridButtonColumn
ButtonType
=
"LinkButton"
Text
=
"delete"
CommandName
=
"Delete"
/>
<
telerik:GridBoundColumn
DataField
=
"name"
HeaderText
=
"Name"
/>
<
telerik:GridTemplateColumn
UniqueName
=
"AssignUsers"
>
<
ItemTemplate
>
<
asp:HyperLink
ID
=
"targetControl"
runat
=
"server"
NavigateUrl
=
"#"
Text
=
"Assign Users"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
div
>
<
asp:EntityDataSource
ID
=
"EntityDataSource1"
runat
=
"server"
ConnectionString
=
"name=EntityFrameworkTestEntities"
DefaultContainerName
=
"EntityFrameworkTestEntities"
EnableDelete
=
"True"
EnableFlattening
=
"False"
EnableInsert
=
"True"
EnableUpdate
=
"True"
EntitySetName
=
"Customers"
Include
=
"Users"
OnDeleted
=
"EntityDataSource1_Deleted"
OnInserting
=
"EntityDataSource1_Inserting"
OnUpdating
=
"EntityDataSource1_Updating"
OnInserted
=
"EntityDataSource1_Inserted"
OnUpdated
=
"EntityDataSource1_Updated"
ViewStateMode
=
"Enabled"
>
</
asp:EntityDataSource
>
</
form
>
</
body
>
</
html
>
assignusers.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="assignusers.ascx.cs" Inherits="assignusers" %>
<%@ Import Namespace="Telerik.Web.UI" %>
<
div
>
<
table
>
<
tr
>
<
td
>Users <
b
>NOT</
b
> Assigned To This Customer</
td
>
<
td
>Users Assigned To This Customer</
td
>
</
tr
>
<
tr
>
<
td
>
<
telerik:RadListBox
ID
=
"RadListBox1"
runat
=
"server"
Width
=
"300px"
Height
=
"200px"
AutoPostBack
=
"false"
SelectionMode
=
"Single"
AllowTransfer
=
"true"
TransferToID
=
"RadListBox2"
AutoPostBackOnTransfer
=
"true"
EnableDragAndDrop
=
"true"
AllowReorder
=
"false"
>
</
telerik:RadListBox
>
</
td
>
<
td
>
<
telerik:RadListBox
ID
=
"RadListBox2"
runat
=
"server"
Width
=
"300px"
Height
=
"200px"
AutoPostBack
=
"false"
SelectionMode
=
"Single"
AllowReorder
=
"false"
EnableDragAndDrop
=
"true"
AutoPostBackOnTransfer
=
"true"
AllowTransfer
=
"true"
TransferToID
=
"RadListBox1"
OnDeleting
=
"RadListBox2_Deleting"
OnInserting
=
"RadListBox2_Inserting"
>
</
telerik:RadListBox
>
</
td
>
</
tr
>
</
table
>
</
div
>
assignusers.ascx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Specialized;
using Telerik.Web.UI;
public partial class assignusers : System.Web.UI.UserControl
{
public int Id
{
get { return Convert.ToInt32(ViewState["id"]); }
set { ViewState["id"] = value.ToString(); }
}
protected void Page_Load(object sender, EventArgs e)
{
RadListBox1.Items.Clear();
RadListBox2.Items.Clear();
using (var context = new EntityFrameworkTestModel.EntityFrameworkTestEntities())
{
if (RadListBox2.DataSource == null)
{
var customer = context.Customers.First(p => p.id == Id);
RadListBox2.DataSource = customer.Users.ToList();
RadListBox2.DataKeyField = "id";
RadListBox2.DataTextField = "name";
RadListBox2.DataValueField = "id";
RadListBox2.DataBind();
}
if (RadListBox1.Items.Count == 0)
{
var users = from u in context.Users
orderby u.name
select u;
foreach (var user in users)
{
if (RadListBox2.FindItemByValue(user.id.ToString()) == null)
{
RadListBoxItem _item = new RadListBoxItem(user.name, user.id.ToString());
RadListBox1.Items.Add(_item);
}
}
}
}
}
protected void RadListBox2_Deleting(object sender, RadListBoxDeletingEventArgs e)
{
using (var context = new EntityFrameworkTestModel.EntityFrameworkTestEntities())
{
var customer = context.Customers.First(p => p.id == Id);
foreach (RadListBoxItem item in e.Items)
{
int _itemid = Convert.ToInt32(item.Value);
var user = context.Users.First(u => u.id == _itemid);
customer.Users.Remove(user);
}
context.SaveChanges();
}
}
protected void RadListBox2_Inserting(object sender, RadListBoxInsertingEventArgs e)
{
using (var context = new EntityFrameworkTestModel.EntityFrameworkTestEntities())
{
var customer = context.Customers.First(p => p.id == Id);
foreach (RadListBoxItem item in e.Items)
{
int _itemid = Convert.ToInt32(item.Value);
var user = context.Users.First(u => u.id == _itemid);
customer.Users.Add(user);
}
context.SaveChanges();
}
}
}
Thanks in advance.
Larry