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

RadComboBox - Find Item by attributes

2 Answers 495 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Martin Gartmann
Top achievements
Rank 2
Martin Gartmann asked on 02 Sep 2010, 11:28 AM
Dear community,

i want to make a preselection on a combobox based on custom attributes on clientside, each time i enter new values to numeric Text boxes.

I have created the attributes on ItemDataBound

Protected Sub cbxKonfektion_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemEventArgs) Handles cbxKonfektion.ItemDataBound
       Dim dataItem As DataRowView = CType(e.Item.DataItem, DataRowView)
       e.Item.Attributes("Gewicht_UG") = dataItem("Gewicht_UG")
       e.Item.Attributes("Gewicht_OG") = dataItem("Gewicht_OG")
       e.Item.Attributes("KGR_UG") = dataItem("KGR_UG")
       e.Item.Attributes("KGR_OG") = dataItem("KGR_OG")
   End Sub

Now i want to compare my custom attributes with two other textboxes each time i have entered a new value in the textbox

As far as i know, there is no method FindItemsByAttribute, right ?

So how to check if my textboxvalue are in the range of the attribute values on clientside, and find the first match.

Any suggestion how to do this task.

Kind regards

Martin Gartmann


2 Answers, 1 is accepted

Sort by
0
Accepted
Veronica
Telerik team
answered on 02 Sep 2010, 02:53 PM
Hello Martin,

If you use  RadTextBoxes you can subscribe to the OnValueChanged client-side event and use the following code in the handler:

Javascript: 
function OnValueChanged(sender, args) {
               var textBox = sender;
               var combo = $find("<%= RadComboBox1.ClientID %>");
               for (var i = 0; i < combo.get_items().get_count(); i++) {
                   var item = combo.get_items().getItem(i);
                   if (sender.get_textBoxValue() == item.get_attributes().getAttribute("Gewicht_UG")) {
                       alert(item.get_text());
                   }
               }
           }

Markup:
<telerik:RadTextBox runat="server" ID="RadTextBox1" ClientEvents-OnValueChanged="OnValueChanged">
       </telerik:RadTextBox>
       <telerik:RadComboBox runat="server" ID="RadComboBox1">
           <Items>
               <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem1" Value="RadComboBoxItem1" />
               <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem2" Value="RadComboBoxItem2" />
               <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem3" Value="RadComboBoxItem3" />
               <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem4" Value="RadComboBoxItem4" />
               <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem5" Value="RadComboBoxItem5" />
               <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem6" Value="RadComboBoxItem6" />
           </Items>
       </telerik:RadComboBox>

Hope this helps.

Best wishes,
Veronica Milcheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Martin Gartmann
Top achievements
Rank 2
answered on 03 Sep 2010, 01:31 PM
Dear Veronica Milcheva,

indeed your post pushed me in the right direction.

So my markup looks like this:

<telerik:RadNumericTextBox ID="rntbHeight" Runat="server" 
                NumberFormat-DecimalDigits="0" CausesValidation="True" 
                Culture="German (Germany)" meta:resourcekey="rntbHeightResource1" 
                ClientEvents-OnValueChanged="checkHeight" 
                Width="125px" MinValue="155" MaxValue="199" ShowSpinButtons="True">
                <ClientEvents OnValueChanged="checkHeight"></ClientEvents>
                <NumberFormat DecimalDigits="0" />

and

          <telerik:RadNumericTextBox ID="rntbGewicht" Runat="server" 
                NumberFormat-DecimalDigits="0" Culture="German (Germany)" 
                meta:resourcekey="rntbGewichtResource1" Width="125px" 
                ClientEvents-OnValueChanged="checkWeight" MinValue="45" MaxValue="105" 
                ShowSpinButtons="True">
<ClientEvents OnValueChanged="checkWeight"></ClientEvents>
                 <NumberFormat DecimalDigits="0" />
            </telerik:RadNumericTextBox>

and the javascript:
 
<script type="text/javascript">
    function checkWeight(sender, args)
    {          var textBox = sender; 
               var combo = $find("<%= cbxKonfektion.ClientID %>"); 
               for(var i = 0; i < combo.get_items().get_count(); i++) {
                   var item = combo.get_items().getItem(i);
                   if(sender.get_textBoxValue() >= item.get_attributes().getAttribute("Gewicht_UG") && sender.get_textBoxValue() <= item.get_attributes().getAttribute("Gewicht_OG") )
                    
                       item.select();
                   
               
           }
            function checkHeight(sender, args)
    {          var textBox = sender; 
               var combo = $find("<%= cbxKonfektion.ClientID %>"); 
               for(var i = 0; i < combo.get_items().get_count(); i++) {
                   var item = combo.get_items().getItem(i);
                   if(sender.get_textBoxValue() >= item.get_attributes().getAttribute("KGR_UG") && sender.get_textBoxValue() <= item.get_attributes().getAttribute("KGR_OG") )
                    
                       item.select();
                   
               
           }
  
</script>

This might be interesting for other user. That's why i post it here.

Preselection for a drowdown based on values on an input field.

Thanks a lot and have a nice weekend.

Martin Gartmann
Tags
ComboBox
Asked by
Martin Gartmann
Top achievements
Rank 2
Answers by
Veronica
Telerik team
Martin Gartmann
Top achievements
Rank 2
Share this question
or