How to add attributes values when adding item in client side

4 posts, 0 answers
  1. Dhamodharan
    Dhamodharan avatar
    300 posts
    Member since:
    Sep 2010

    Posted 27 Apr 2011 Link to this post

    Hi,

    I am using radlistbox. i added the items into radlistbox in client side. it is fine. but how to add attributes for the item?

    var list = $find("<%= RadListBoxSource.ClientID %>");
                         var items = list.get_items(); list.trackChanges();
                         var item = new Telerik.Web.UI.RadListBoxItem();
                         item.set_text(txt);
                         item.set_value(val);
                         list.get_items().getItem().set_attributes().setAttribute('display_list') = "list1";
                         list.get_items().add(item);
                         item.select();
                         list.commitChanges();

    Bold items i am not able to add attributes for this one.

    Please let me know if you have any tips,

    Thanks,
    Dhamu,
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 Apr 2011 Link to this post

    Hello Dhamu,

    Take a look at the following documentation.
    RadListBoxItem client API

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dhamodharan
    Dhamodharan avatar
    300 posts
    Member since:
    Sep 2010

    Posted 27 Apr 2011 Link to this post

    Hi Princy,

    I am not clear about this example.

    Please check my code,

    <telerik:RadListBox
            runat="server" ID="RadListBoxSource"
            Height="200px" Width="200px"
            AllowTransfer="true" TransferToID="RadListBoxDestination" AllowReorder="false" DataTextField="uname" DataSourceID="SqlDataSource3"  OnClientItemDoubleClicked="setText" AppendDataBoundItems="true">
            <Items>
            <telerik:RadListBoxItem Text="All Items" Value="list1"  Selected="true"/>        
            </Items><ButtonSettings ShowTransferAll="false" ShowTransfer="false" />
        </telerik:RadListBox>

    Code behind
    -----------------
    Protected Sub RadListBoxSource_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListBoxItemEventArgs) Handles RadListBoxSource.ItemDataBound

            If TypeOf e.Item Is RadListBoxItem Then
                e.Item.Attributes("display_order") = i + 1
                e.Item.Attributes("display_list") = "list1"
            End If
            i += 1
        End Sub


    Client side,
    ---------------
       var list = $find("<%= RadListBoxSource.ClientID %>");
                         var items = list.get_items(); list.trackChanges();
                         var item = new Telerik.Web.UI.RadListBoxItem();
                         item.set_text(txt);
                         item.set_value(val);               
                       list.get_items(order).add(item);                  
                       item.select();
                         list.commitChanges();

    It is all working fine..
    I am using two attributes in code behind. there is "display_order" and "display_list". so now i am adding value in client side how to set values for these attributes.

    Please let me know,

    Thanks,
    Dhamu.
  5. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 02 May 2011 Link to this post

    Hi dhamodharan,

    After you add the attributes you need to find the item from the RadListBox client object and set the attributes values.
    Here is an example:
    var listbox = $find("<%= RadListBox1.ClientID %>");
    var foundItem = listbox.findItemByAttribute("display_list", "list1");
    var attributes = foundItem.get_attributes();
    attributes.setAttribute("display_list", "newValue");


    Kind regards,
    Peter Filipov
    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