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

[Solved] Problem with Attribute

2 Answers 241 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
FAR
Top achievements
Rank 1
FAR asked on 23 Nov 2009, 05:18 PM
Hello,

 i have this javascript code

   function AccesDirectFicheCadre() { 
                var cb = $find("<%= AccesDirect_List.ClientID %>"); 
                var item = cb.get_selectedItem(); 
                 
                var id = item.get_attributes().getAttribute('Id'); 
           // Some other actions using "id", but "id" is ALWAYS undefined... :( 
            } 

With this :

   <telerik:RadComboBox  
                    runat="server" ID="AccesDirect_List"    OnClientItemsRequested="OnClientItemsRequested" 
 ShowDropDownOnTextboxClick="false" 
                 MarkFirstMatch="true"  
                 EnableVirtualScrolling="true" NoWrap="true" MaxHeight="210px" 
                    EnableLoadOnDemand="true"  
                    HighlightTemplatedItems="true" EnableViewState="false" 
                    OnItemDataBound="RadComboBox1_ItemDataBound"  
                    OnItemsRequested="RadComboBox1_ItemsRequested"
                </telerik:RadComboBox> 

and this
       protected void RadComboBox1_ItemDataBound(object sender, RadComboBoxItemEventArgs e) 
        { 
            //set the Text and Value property of every item 
            //here you can set any other properties like Enabled, ToolTip, Visible, etc. 
            e.Item.Text = ((DataRowView)e.Item.DataItem)["Nom"].ToString(); 
            e.Item.Value = ((DataRowView)e.Item.DataItem)["Id_Cadre"].ToString(); 
            e.Item.Attributes["Id"] = ((DataRowView)e.Item.DataItem)["Id_Cadre"].ToString(); 
        } 




The problem is that in my javascript function, the "id" is ALWAYS undefined, i'm unable to access the "Attribute" value i have set in the codebehind method.

How can i do this ?

Thank you

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 24 Nov 2009, 10:42 AM
Hello,

Can you change the attribute name other than 'Id' and see whether it is working? I tried different name and got it working.

cs:
 
    protected void RadComboBox1_ItemDataBound(object sender, Telerik.Web.UI.RadComboBoxItemEventArgs e) 
    { 
        e.Item.Text = ((DataRowView)e.Item.DataItem)["CategoryName"].ToString(); 
        e.Item.Attributes["myId"] = ((DataRowView)e.Item.DataItem)["CategoryID"].ToString();  
    } 

javascript:
 
<script type="text/javascript"
    function AccesDirectFicheCadre() { 
        var cb = $find("<%= AccesDirect.ClientID %>"); 
        var item = cb.get_selectedItem(); 
        var id1 = item.get_attributes().getAttribute('myId'); 
        alert(id1); 
    } 
</script> 

-Shinu.
0
FAR
Top achievements
Rank 1
answered on 24 Nov 2009, 01:25 PM
Yeah it's working now, thank you.
I don't know why the "Id" is forbiddenn...


Tags
ComboBox
Asked by
FAR
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
FAR
Top achievements
Rank 1
Share this question
or