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

Trouble with RadListBox .findItemByValue()

4 Answers 229 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Clayton Page
Top achievements
Rank 1
Clayton Page asked on 26 Jan 2011, 07:12 PM
I am trying to implement the radListBox into a project I am working on and I am having an issue removing an item from the listbox via JavaScript. I am trying to use the .findItemByValue function to get the ListBoxItem I need to remove but this function returns a value of undefined. I can get the item by using the .get_items().getitem(index) but when I call the .get_value() function I get a return value of "Telerik.Web.UI.RadListBoxItem". I am using an item template to add a delete link to the item and databinding a List<Telerik.Web.UI.RadListBoxItem> to the ListBox. I have been trying to figure this out all day. Any help would be greatly appreciated.

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Jan 2011, 06:55 AM
Hello Clayton.

I was unable to recreate the same scenario. Here am pasting the code that I tried.Please do a double check with your code and check whether you have missed anything .  

aspx:
<telerik:RadListBox ID="RadListBox1" runat="server"  DataTextField="LastName"  AutoPostBack="true" DataSourceID="SqlDataSource1"Height="50px" DataValueField="EmployeeID" >
 <ItemTemplate>
            <asp:LinkButton ID="lnkBtn1" runat="server" Text="Delete" OnClientClick="Delete();">
             </asp:LinkButton>
            <%# DataBinder.Eval(Container, "Text")%>
 </ItemTemplate>
</telerik:RadListBox>

Javascript:
function Delete(sender, args)
 {
    var listBox = $find('<%=RadListBox1.ClientID%>');
    var getValue=listBox.get_items().getItem(8).get_value();
 }

Thanks,
Shinu.
0
Kate
Telerik team
answered on 28 Jan 2011, 10:47 AM
Hello Clayton,

I explored the issue and it seems that the function findItemByValue on the client side works just fine. Here I have attached a sample project with the same scenario that you describe.

Please let me know how it goes.

All the best,
Kate
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Clayton Page
Top achievements
Rank 1
answered on 09 Feb 2011, 12:34 AM
Thanks for getting back to me. I am still having the same issue. below is my code.

Markup
<telerik:RadListBox ID="CourseListRadListBox" runat="server" OnItemDataBound="CourseListRadListBox_ItemDataBound">
    <
ItemTemplate>
  
        <%#(Container.DataItem as RadListBoxItem).Text %>
                                             
        <
asp:HyperLink ID="RemoveCourseHyperlink" runat="server" ImageUrl="~/shared/images/icon_delete.gif" NavigateUrl="#"></asp:HyperLink>
                                                  
    </
ItemTemplate>
                                               
</
telerik:RadListBox>

DataBinding:
protected void CourseListRadListBox_ItemDataBound(Object sender, RadListBoxItemEventArgs e)
{

    HyperLink removeCourseHyperlink =
null;
 
    if
(e.Item.FindControl("RemoveCourseHyperlink") != null)

        removeCourseHyperlink = e.Item.FindControl(
"RemoveCourseHyperlink") as HyperLink;
 
    if
(removeCourseHyperlink != null)

        removeCourseHyperlink.Attributes.Add(
"onclick", "RemoveCourseFromGroup(" + (e.Item.DataItem as RadListBoxItem).Value + ")");

}

JavaScript:
function RemoveCourseFromGroup(CourseId) {
    var
listbox = $find("ctl00_body_LearningPathGroupsListView_ctrl0_CourseListRadListBox");

    var
item = listbox.findItemByValue(CourseId);
 
    listbox.trackChanges();

    listbox.get_items().remove(item);

    listbox.commitChanges();
}


the listbox.findItemByValue(CourseId) returns null and listbox.get_items().getItem(0).get_value() returns "Telerik.Web.UI.RadListBoxItem". Any help would be appreciated.

Thanks again.
0
Kate
Telerik team
answered on 10 Feb 2011, 05:26 PM
Hello Clayton Page,

The code that you provide does not show where exactly you set the value of the items. Can you please send us a runnable page to see where the problem comes from?

Regards,
Kate
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
ListBox
Asked by
Clayton Page
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Kate
Telerik team
Clayton Page
Top achievements
Rank 1
Share this question
or