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

Get values from ItemTemplate OnClientSelectedIndexChanged

4 Answers 347 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
KorsG
Top achievements
Rank 1
KorsG asked on 26 Apr 2010, 07:21 PM
Hi,
I have a combobox, that when changed, should change the selected value of 2 other comboboxed based on the selection.

<telerik:RadComboBox ID="RadComboBox1" runat="server"  DataTextField="Name" DataValueField="ActTypeNo"                                              
    OnClientSelectedIndexChanged="OnClientSelectedIndexChanged"  > 
<ItemTemplate> 
    <table> 
       <tr> 
         <td style="width: 200px;"
                 <asp:Label ID="ChaufName" runat="server" EnableViewState="false" Text='<%#DataBinder.Eval(Container.DataItem, "Name")%>'></asp:Label> 
         </td> 
       <td style="display:none;"
           <asp:Label ID="ChaufGr1" runat="server" EnableViewState="false" Text='<%#DataBinder.Eval(Container.DataItem, "Gr1")%>'></asp:Label> 
           </td> 
       <td style="display:none;"
           <asp:Label ID="ChaufGr2" runat="server" EnableViewState="false" Text='<%#DataBinder.Eval(Container.DataItem, "Gr2")%>'></asp:Label> 
           </td> 
       </tr> 
</table> 
</ItemTemplate> 
 </telerik:RadComboBox> 

My goal is to get the values of "ChaufGr1" and "ChaufGr2" in a javascript function:
function OnClientSelectedIndexChanged(sender, args) { 
                //get values 
               
                //set selected value of other combos - i know how to do this 
            } 

I have searched the documentation and forums, but i couldn't find anything exactly like this. 
Can you point me in the right direction?

4 Answers, 1 is accepted

Sort by
0
Accepted
robertw102
Top achievements
Rank 1
answered on 26 Apr 2010, 08:44 PM
You should them as attributes to the RadComboBoxItem similar to this RadListBox example:


So you could loop through the RadComboBox.Items collection and add the attributes to each one. Then you can retrieve the values from the attributes collection.

I hope that helps.
0
Accepted
Shinu
Top achievements
Rank 2
answered on 27 Apr 2010, 09:43 AM

Hello,

In fact, Robert said is correct. You can make use of custom attribute in order to get additional values. Here is the example that I tried for similar scenario.

CS:

 
    protected void RadComboBox1_ItemDataBound(object sender, Telerik.Web.UI.RadComboBoxItemEventArgs e)  
    {  
        DataRowView dataSourceRow = (DataRowView)e.Item.DataItem;  
        //set custom attributes from the datasource:      
        e.Item.Attributes["Gr1"] = dataSourceRow["Gr1"].ToString();  
        e.Item.Attributes["Gr2"] = dataSourceRow["Gr2"].ToString();    
    } 

JavaScript:

 
<script type="text/javascript">  
    function OnClientSelectedIndexChanged(sender, args) {  
        var item = args.get_item();  
        // Alert the values  
        alert(item.get_attributes().getAttribute("Gr1"));  
        alert(item.get_attributes().getAttribute("Gr2"));  
    }  
</script> 

-Shinu.

0
KorsG
Top achievements
Rank 1
answered on 28 Apr 2010, 03:18 PM
Thank you both, this helped me solve my problem! :-)

My final js and code behind ended up like this:
function OnClientSelectedIndexChanged(sender, args) { 
                //get values 
                var item = args.get_item(); 
                var gr1ID = item.get_attributes().getAttribute("Gr1"); 
                var gr2ID = item.get_attributes().getAttribute("Gr2"); 
                //set values 
                var gr1Combo = $find("<%=Gr1Combo.ClientID%>"); 
                var gr1Item = gr1Combo.findItemByValue(gr1ID); 
                if (gr1Item) { 
                    gr1Item.select(); 
                } 
                var gr2Combo = $find("<%=Gr2Combo.ClientID%>"); 
                var gr2Item= gr2Combo.findItemByValue(gr2ID); 
                if (gr2Item) { 
                    gr2Item.select(); 
                } 

As i use a LinqDataSource i had to use the databinder
Protected Sub Chauffeurs_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemEventArgs) Handles Chauffeurs.ItemDataBound  
        e.Item.Attributes("Gr1") = DataBinder.Eval(e.Item.DataItem, "Gr1")  
        e.Item.Attributes("Gr2") = DataBinder.Eval(e.Item.DataItem, "Gr2")  
    End Sub  
 


0
Aruldoss
Top achievements
Rank 1
answered on 02 Nov 2017, 05:35 AM

how to get ComboBox Value

       List<Student> students=new List<Student>();

           Student student1=new Student();

             student1.Id=1;

             student1.Name="Name1";

             student1.Code="code1";

             students.Add(student1);

 

           Student student2=new Student();
             student2.Id=2;
             student2.Name="Name2";
             student2.Code="code2";
             students.Add(student2);

 

            RadComboBox1.DataSource = students;
            RadComboBox1.DataTextField = "Name";
            RadComboBox1.DataValueField = "Id";
            RadComboBox1.DataBind();

how to get Student of code from selected combobox value

 

 

 

 

Tags
ComboBox
Asked by
KorsG
Top achievements
Rank 1
Answers by
robertw102
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
KorsG
Top achievements
Rank 1
Aruldoss
Top achievements
Rank 1
Share this question
or