Trouble with RadListBox .findItemByValue()

5 posts, 0 answers
  1. Clayton Page
    Clayton Page avatar
    2 posts
    Member since:
    Apr 2010

    Posted 26 Jan 2011 Link to this post

    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.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Jan 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 28 Jan 2011 Link to this post

    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.
  5. Clayton Page
    Clayton Page avatar
    2 posts
    Member since:
    Apr 2010

    Posted 08 Feb 2011 Link to this post

    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.
  6. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 10 Feb 2011 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017