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

RadListBox OnSelectedIndexChanged JS Error

2 Answers 43 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Jeremy
Top achievements
Rank 1
Jeremy asked on 05 Aug 2014, 03:04 PM

I'm having trouble with the RadListBox on selected index changed. OnSelectedIndexChanged does not fire an event at all and OnClientSelectedIndexChanged gives a JS error.
I'm using the RadListBoxes to move items around as described in http://demos.telerik.com/aspnet-ajax/listbox/examples/overview/defaultcs.aspx#qsf-demo-source
 
But I also need to display information about the single selected item so the user knows if this is the right item to move.  But I'm getting a Error: 'AllGroupsRadListBox_SelectedIndexChanged' is undefined.

<telerik:RadListBox runat="server" ID="AllGroupsRadListBox" Height="200px" Width="200px" AllowTransfer="true" SelectionMode="Single" TransferToID="SharedGroupsRadListBox" OnClientSelectedIndexChanged="AllGroupsRadListBox_SelectedIndexChanged" />
<telerik:RadListBox runat="server" ID="SharedGroupsRadListBox" Height="200px" Width="200px" /><br />
Users in selected group:<br />
<telerik:RadListBox runat="server" ID="UsersRadListBox" Height="200px" Width="200px" />
  
private void FillAllGroups()
{
 BWGroups allGroups = new BWGroups();
 allGroups.GetAllBWGroups();
  
 AllGroupsRadListBox.DataTextField = "BWGroupName";
 AllGroupsRadListBox.DataValueField = "BWGroupID";
 AllGroupsRadListBox.DataSource = allGroups.BWGroupList;
 AllGroupsRadListBox.DataBind();
}
  
protected void AllGroupsRadListBox_SelectedIndexChanged(object sender, EventArgs e)
{
int parseGroupId = -1; Int32.TryParse(AllGroupsRadListBox.SelectedValue.ToString(), out parseGroupId);
BWUsers usersInGroup = new BWUsers();
  
if(parseGroupId > 0)
 usersInGroup.GetActiveBWUsersByGroupID(parseGroupId);
  
UsersRadListBox.DataTextField = "BWGroupName";
UsersRadListBox.DataValueField = "BWGroupID";
UsersRadListBox.DataSource = usersInGroup.BWUserList;
UsersRadListBox.DataBind();
}

2 Answers, 1 is accepted

Sort by
0
Jeremy
Top achievements
Rank 1
answered on 05 Aug 2014, 08:50 PM
To add another question into the mix.  Once I drag an item from one RadListBox to the TransferTo RadListBox, I want the item I just moved defaulted to selected in the TransferTo RadListBox.  So when I drage a group from AllGroupsRadListBox into SharedGroupsRadListBox, I want the SharedGroupsRadListBox copy of the group to be selected so that the user can then do what he/she needs to do with the Group they just copied without having to then click on it again (my users are very click averse and quite vocal about it).
0
Shinu
Top achievements
Rank 1
answered on 06 Aug 2014, 07:46 AM

Hi Jeremy,

In order to fire the OnSelectedIndexChanged event of RadListBox please try to set the AutoPostBack property of RaListBox to true. The OnClientSelectedIndexChanged event is working fine at my end. Please have a look into the sample code snippet.

ASPX:

<telerik:RadListBox runat="server" ID="AllGroupsRadListBox" Height="200px" Width="200px"AutoPostBack="true" AllowTransfer="true" SelectionMode="Single" TransferToID="SharedGroupsRadListBox" OnClientSelectedIndexChanged="changeSelection" OnSelectedIndexChanged="AllGroupsRadListBox_SelectedIndexChanged"/>

JavaScript:
function changeSelection(sender, e) {
    alert("fired");
}

C#:
protected void AllGroupsRadListBox_SelectedIndexChanged(object sender, EventArgs e)
{
    //your code
}

As for your second question try to set the TransferMode propert of RadListBox to Copy, it will only copy the items to the destination RadListBox.

Thanks,
Shinu.
Tags
ListBox
Asked by
Jeremy
Top achievements
Rank 1
Answers by
Jeremy
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Share this question
or