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

How to add attributes values when adding item in client side

3 Answers 450 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Dhamodharan
Top achievements
Rank 1
Dhamodharan asked on 27 Apr 2011, 10:24 AM
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,

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Apr 2011, 11:08 AM
Hello Dhamu,

Take a look at the following documentation.
RadListBoxItem client API

Thanks,
Princy.
0
Dhamodharan
Top achievements
Rank 1
answered on 27 Apr 2011, 12:37 PM
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.
0
Peter Filipov
Telerik team
answered on 02 May 2011, 08:52 AM
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.

Tags
ListBox
Asked by
Dhamodharan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Dhamodharan
Top achievements
Rank 1
Peter Filipov
Telerik team
Share this question
or