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

comboBox and OnClientSelectedIndexChanged Problem

7 Answers 296 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
maha
Top achievements
Rank 1
maha asked on 05 Aug 2010, 02:56 PM
I have the following code

      <telerik:RadComboBox ID="RadComboBoxCat" OnClientSelectedIndexChanged="setText" runat="server" Width="138px"  EnableEmbeddedSkins="false"  Font-Size="8pt" Font-Names="tahoma" ForeColor="White" skin="comboSkin" />
  
<script type="text/javascript" language="javascript">
    function setText() {
         
        document.getElementById("<%=btnsearch1.ClientID %>").click();
  
    }

RadComboBoxCat.DataSource = dtCategories
                RadComboBoxCat.DataTextField = "subject"
                RadComboBoxCat.DataValueField = "subjectcode"
                RadComboBoxCat.DataBind()
  
 Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnSearch.Click
            Dim url As String
                        Dim str = txtSearch.Text
            For j As Integer = 0 To str.Length - 1
                If (str.Contains("+")) Then
                    str = str.Replace("+", "%2B")
                End If
            Next
            url = hrefpath & "locate.aspx?search=" & RadComboBoxSearch.SelectedValue             Response.Redirect(url)

End Sub

So the combox Box will load items in it with the 1st one diplayed and one try to click on any item the function as shown will redirect to another page.But my problem is when i click on 1st item the function is not called since the comboBox considers that the index was not changed. How can i do that without adding a dummy text and value as 1st item?

7 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 05 Aug 2010, 03:14 PM
Hello maha,

Instead of the client-side SelectedIndexChanged event you can use the following code:
(function ($) {
    $(".rcbItem").click(function () {
        // handle item click
    });
})($telerik.$);

The code put at the place of the comment will execute every time you click on any item.

I hope this helps.

Greetings,
Simon
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
maha
Top achievements
Rank 1
answered on 07 Aug 2010, 09:45 AM
How to check or get the item value selected inside that function?
0
Simon
Telerik team
answered on 11 Aug 2010, 09:21 AM
Hello maha,

Each Item element has an expando named "_item" so you can get the reference to the Item object through it, e.g.
(function ($) {
    $(".rcbItem").click(function () {
        var item = this._item;
    });
})($telerik.$);

Regards,
Simon
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
maha
Top achievements
Rank 1
answered on 16 Aug 2010, 08:16 AM
I wanna get the item selected value.I tried item.value but didnt work.what can i use?
0
Simon
Telerik team
answered on 16 Aug 2010, 02:41 PM
Hello maha,

You can get the value of the Item by calling item.get_value().

Here is a list with the most commonly used client-side methods and properties of the RadComboBoxItem object.

Kind regards,
Simon
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
maha
Top achievements
Rank 1
answered on 17 Aug 2010, 01:10 PM
I am receiving this javascript error :

 'item' is null or not an object

And another problem i have two comboBox in the page I want the  function to be called for only one comboBox.

(function($) {

 

 $(".rcbItem").click(function() {

 

 

// // handle item click

 

 

 var item = this._item;

 

 

alert(item.get_value());

 

 

 });
})($telerik.$);

 

0
Simon
Telerik team
answered on 20 Aug 2010, 11:00 AM
Hello maha,

I just tested the code again and it worked find. Additionally you can limit the event attaching to only one RadComboBox if you use a context. Below is an example for both requirements:

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
    <telerik:RadComboBox ID="RadComboBox1" runat="server" OnClientLoad="onLoad">
        <Items>
            <telerik:RadComboBoxItem Text="1" />
            <telerik:RadComboBoxItem Text="2" />
            <telerik:RadComboBoxItem Text="3" />
        </Items>
    </telerik:RadComboBox>
 
    <telerik:RadComboBox ID="RadComboBox2" runat="server">
        <Items>
            <telerik:RadComboBoxItem Text="1" />
            <telerik:RadComboBoxItem Text="2" />
            <telerik:RadComboBoxItem Text="3" />
        </Items>
    </telerik:RadComboBox>
</div>
</form>
<script type="text/javascript">
    function onLoad(sender) {
        $telerik.$(".rcbItem", sender.get_dropDownElement())
            .click(function () {
                var item = this._item;
                alert(item.get_text());
            });
    }
</script>

I hope this helps.

All the best,
Simon
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
Tags
ComboBox
Asked by
maha
Top achievements
Rank 1
Answers by
Simon
Telerik team
maha
Top achievements
Rank 1
Share this question
or