I have two listboxes ton transfer the list items from Source to Destination listbox.The destination listbox item template has 4 Controls all set to visible false.
in ListBox Transferred event , I am checking ,
if the Source is "SourceListBox" then
for each item in e.Items
Item.FindControl("Controlid") converting to respective item
item.DataBind()
End
In 2010 telerik dll version , The above code works properly .
However in 2013 dll version , the above code throws error when second item gets transferred to Destination list box i.e. " Item.FindControl("Controlid") converting to respective item" returns null value.
Note: When first item is transferred from Source to Destination list box it works well, Issue is only when second item is transferred...which is really strange ..that too this codew works very well in 2010 vesrion.
Please let me know if this known issue...or any thing wrong
5 Answers, 1 is accepted
Would you paste the markup, demonstrating the implementation of the RadListBoxes that you are currently using, along with the configured ItemTemplates?
Regards,
Nencho
Telerik
1.First ListView
<
telerik:RadListBox
ID
=
"AttributesListBox"
runat
=
"server"
AllowTransfer
=
"true"
AutoPostBackOnTransfer
=
"true"
Height
=
"220px"
OnTransferred
=
"AttributesListBox_Transferred"
SelectionMode
=
"Multiple"
TransferToID
=
"FilterCriteriaListBox"
Width
=
"215px"
EnableDragAndDrop
=
"true"
CssClass
=
"RadListBox-custom"
>
<
ButtonSettings
ShowTransferAll
=
"false"
VerticalAlign
=
"Middle"
></
ButtonSettings
>
<
ItemTemplate
>
<
span
style
=
"float: left; clear: both; font-weight: bolder"
>
<
div
style
=
"display: none"
>
<%# DataBinder.Eval(Container, "Attributes['AttributeType']")%>
<%# DataBinder.Eval(Container, "Attributes['GName']")%></
div
>
<
div
>
<%# DataBinder.Eval(Container, "Attributes['GroupName']")%></
div
>
</
span
><
span
style
=
"float: left; clear: both; margin-left: 5px;"
>
<%# DataBinder.Eval(Container, "Attributes['AttributeName']")%>
</
span
>
</
ItemTemplate
>
</
telerik:RadListBox
>
2.Second ListView
<
telerik:RadListBox
runat
=
"server"
ID
=
"FilterCriteriaListBox"
Height
=
"220px"
Width
=
"370px"
OnItemDataBound
=
"FilterCriteriaListBox_ItemDatBound"
SelectionMode
=
"Multiple"
EnableDragAndDrop
=
"true"
CssClass
=
"RadListBox-custom"
>
<
ItemTemplate
>
<
ul
class
=
"ul-form"
>
<
li
>
<
label
style
=
"color: Purple; float: left; margin-right: 10px"
>
<%# DataBinder.Eval(Container, "Attributes['AttributeName']")%>
:</
label
>
<
div
style
=
"display: none"
>
<%# DataBinder.Eval(Container, "Attributes['AttributeType']")%></
div
>
<
div
style
=
"display: none"
>
<%# DataBinder.Eval(Container, "Attributes['GName']")%></
div
>
<
div
class
=
"fontstyle14"
>
<
asp:TextBox
runat
=
"server"
ID
=
"textTypeInput"
Width
=
"120px"
Visible
=
"false"
Style="float: left;
clear: both">
</
asp:TextBox
>
</
div
>
<
div
class
=
"fontstyle14"
>
<
telerik:RadComboBox
runat
=
"server"
ID
=
"listTypeInput"
Width
=
"120px"
MinValue
=
"1"
Visible
=
"false"
MaxValue
=
"10"
ShowSpinButtons
=
"true"
Style
=
"float: left; clear: both"
Value
=
"1"
NumberFormat-DecimalDigits
=
"0"
Height
=
"150"
>
</
telerik:RadComboBox
>
</
div
>
<
div
class
=
"fontstyle14"
>
<
telerik:RadSlider
runat
=
"server"
ID
=
"sliderTypeInput"
Height
=
"50px"
Width
=
"120px"
MinValue
=
"1"
SmallChange
=
"75"
LargeChange
=
"110"
Visible
=
"false"
ShowSpinButtons
=
"true"
MaxValue
=
"1000"
Style
=
"float: left; clear: both"
TrackPosition
=
"BottomRight"
ItemType
=
"Tick"
>
</
telerik:RadSlider
>
</
div
>
<
div
class
=
"fontstyle14"
>
<
asp:CheckBoxList
ID
=
"optionTypeInput"
runat
=
"server"
Style
=
"float: left; clear: both"
Visible
=
"false"
>
</
asp:CheckBoxList
>
</
div
>
</
li
>
</
ul
>
</
ItemTemplate
>
</
telerik:RadListBox
>
and the code behind,
protected void AttributesListBox_Transferred(object sender, RadListBoxTransferredEventArgs e)
{
foreach (RadListBoxItem item in e.Items)
{
if (e.SourceListBox == AttributesListBox)
{
SetFilterControlVisibility(item.Attributes["AttributeType"], item);
}
else
{
int transferredItemsCount = e.Items.Count;
int destItemsCount = 0;
int insertPosition = 0;
destItemsCount = AttributesListBox.TransferToListBox.Items.Count;
IEnumerable<
RadListBoxItem
> items = AttributesListBox.Items.ToList<
RadListBoxItem
>();
insertPosition = destItemsCount - transferredItemsCount;
int index = AttributesListBox.Items.Where(listItem => listItem.Attributes["AttributeType"] == null && listItem.Attributes["GroupName"] == item.Attributes["GName"]).First().Index;
RadListBoxItem transferredItem = item;
item.Remove();
AttributesListBox.Items.Insert(index+1, transferredItem);
}
item.DataBind();
}
}
private bool SetFilterControlVisibility(string type, RadListBoxItem item)
{
switch (type)
{
case "Text":
TextBox textBox = (TextBox)item.FindControl("textTypeInput");
//Data binding
break;
case "List":
RadComboBox radComboBox = (RadComboBox)item.FindControl("listTypeInput");
//Data binding
break;
case "Slider":
RadSlider radSlider = (RadSlider)item.FindControl("sliderTypeInput");
//Data binding
radSlider.Visible = true;
break;
case "Options":
CheckBoxList checkBoxList = (CheckBoxList)item.FindControl("optionTypeInput");
checkBoxList.Items.Clear();
//Data binding
checkBoxList.Visible = true;
break;
default: break;
}
return true;
}
I tried to replicate the described issue, but to no avail. The functionality seems the work properly at my end. I had prepared a sample project for you with a custom data for the sake of the example. Please find it attached and let me know if the issue still persist at your end.
Regards,
Nencho
Telerik
Thanks for update, I downloaded and tried running your project with diffrent datasource(List ), but no luck.
I still face same issue. Updated code behind code and aspx markup copied below for reference, Please let me know if am missing any thing here.
It would be great if you can reply ASAP with the modifications required.
ASPX:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<telerik:RadScriptManager runat="server">
</telerik:RadScriptManager>
<div>
<telerik:RadListBox ID="AttributesListBox" runat="server" AllowTransfer="true" AutoPostBackOnTransfer="true"
Height="220px" OnTransferred="AttributesListBox_Transferred" SelectionMode="Multiple"
TransferToID="FilterCriteriaListBox" Width="215px" EnableDragAndDrop="true" CssClass="RadListBox-custom">
<ButtonSettings ShowTransferAll="false" VerticalAlign="Middle"></ButtonSettings>
<ItemTemplate>
<span style="float: left; clear: both; font-weight: bolder">
<div style="display: none">
<%# DataBinder.Eval(Container, "Attributes['ProductID']")%>
<%# DataBinder.Eval(Container, "Attributes['UnitPrice']")%>
</div>
<div>
<%# DataBinder.Eval(Container, "Attributes['UnitsInStock']")%>
</div>
</span><span style="float: left; clear: both; margin-left: 5px;">
<%# DataBinder.Eval(Container, "Attributes['ProductName']")%>
</span>
</ItemTemplate>
</telerik:RadListBox>
<telerik:RadListBox runat="server" ID="FilterCriteriaListBox" Height="220px" Width="370px"
OnItemDataBound="FilterCriteriaListBox_ItemDataBound" SelectionMode="Multiple"
EnableDragAndDrop="true" CssClass="RadListBox-custom">
<ItemTemplate>
<ul class="ul-form">
<li>
<label style="color: Purple; float: left; margin-right: 10px">
<%# DataBinder.Eval(Container, "Attributes['ProductName']")%>
:</label>
<div style="display: none">
<%# DataBinder.Eval(Container, "Attributes['ProductID']")%>
</div>
<div style="display: none">
<%# DataBinder.Eval(Container, "Attributes['UnitPrice']")%>
</div>
<div>
<%# DataBinder.Eval(Container, "Attributes['UnitsInStock']")%>
</div>
<div class="fontstyle14">
<asp:TextBox runat="server" ID="input" Width="120px" Visible="false" Style="float: left;
clear: both">
</asp:TextBox>
</div>
<div class="fontstyle14">
<telerik:RadComboBox runat="server" ID="list" Width="120px" MinValue="1"
Visible="false" MaxValue="10" ShowSpinButtons="true" Style="float: left; clear: both"
Value="1" NumberFormat-DecimalDigits="0" Height="150">
</telerik:RadComboBox>
</div>
<div class="fontstyle14">
<telerik:RadSlider runat="server" ID="slider" Height="50px" Width="120px"
MinValue="1" SmallChange="75" LargeChange="110" Visible="false" ShowSpinButtons="true"
MaxValue="1000" Style="float: left; clear: both" TrackPosition="BottomRight"
ItemType="Tick">
</telerik:RadSlider>
</div>
<div class="fontstyle14">
<asp:CheckBoxList ID="options" runat="server" Style="float: left; clear: both"
Visible="false">
</asp:CheckBoxList>
</div>
</li>
</ul>
</ItemTemplate>
</telerik:RadListBox>
</div>
</form>
</body>
</html>
Code behind file:
using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
populateListBox();
}
protected void populateListBox()
{
//string sqlSelectCommand = "SELECT [ProductID], [ProductName], [UnitPrice], [UnitsInStock] from [Products] ORDER BY [ProductName]";
//SqlDataAdapter adapter = new SqlDataAdapter(sqlSelectCommand,
// ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
//DataTable dataTable = new DataTable();
//adapter.Fill(dataTable);
List<Product> list = GetList();
foreach (Product reportAttribute in list)
{
RadListBoxItem item = new RadListBoxItem();
item.Attributes.Add("ProductName", reportAttribute.ProductName);
item.Attributes.Add("ProductID", reportAttribute.ProductID);
item.Attributes.Add("UnitPrice", reportAttribute.UnitPrice);
item.Attributes.Add("UnitsInStock", reportAttribute.UnitsInStock);
AttributesListBox.Items.Add(item);
item.DataBind();
}
}
private List<Product> GetList()
{
List<Product> theList = new List<Product>();
theList.Add(new Product { ProductName = "prod1", ProductID = "id1", UnitPrice = "123", UnitsInStock="asd" });
theList.Add(new Product { ProductName = "prod2", ProductID = "id1", UnitPrice = "123", UnitsInStock = "asd" });
theList.Add(new Product { ProductName = "prod3", ProductID = "id1", UnitPrice = "12312", UnitsInStock = "asd" });
theList.Add(new Product { ProductName = "prod4", ProductID = "id1", UnitPrice = "123123", UnitsInStock = "asd" });
return theList;
}
public class Product
{
public string ProductName { get; set; }
public string ProductID { get; set; }
public string UnitPrice { get; set; }
public string UnitsInStock { get; set; }
}
protected void AttributesListBox_Transferred(object sender, RadListBoxTransferredEventArgs e)
{
foreach (RadListBoxItem item in e.Items)
{
if (e.SourceListBox == AttributesListBox)
{
SetFilterControlVisibility(item.Attributes["ProductName"], item);
}
item.DataBind();
}
}
private bool SetFilterControlVisibility(string type, RadListBoxItem item)
{
switch (type)
{
case "prod1":
TextBox textBox = (TextBox)item.FindControl("input");
//Data binding
textBox.Visible = true;
break;
case "prod2":
RadComboBox radComboBox = (RadComboBox)item.FindControl("list");
radComboBox.Visible = true;
break;
case "prod3":
RadSlider radSlider = (RadSlider)item.FindControl("slider");
radSlider.Visible = true;
break;
case "prod4":
CheckBoxList checkBoxList = (CheckBoxList)item.FindControl("options");
checkBoxList.Visible = true;
break;
default: break;
}
return true;
}
protected void FilterCriteriaListBox_ItemDataBound(object sender, RadListBoxItemEventArgs e)
{
}
}
Thanks
Akash
I was able to replicate the described issue and it seems like this is a bug. I have already forwarded it to our developer team for further investigation. Thank you for pointing that out.
Regards,
Nencho
Telerik