comboBox and OnClientSelectedIndexChanged Problem

8 posts, 0 answers
  1. maha
    maha avatar
    44 posts
    Member since:
    Jun 2010

    Posted 05 Aug 2010 Link to this post

    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?
  2. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 05 Aug 2010 Link to this post

    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
  3. maha
    maha avatar
    44 posts
    Member since:
    Jun 2010

    Posted 07 Aug 2010 Link to this post

    How to check or get the item value selected inside that function?
  4. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 11 Aug 2010 Link to this post

    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
  5. maha
    maha avatar
    44 posts
    Member since:
    Jun 2010

    Posted 16 Aug 2010 Link to this post

    I wanna get the item selected value.I tried item.value but didnt work.what can i use?
  6. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 16 Aug 2010 Link to this post

    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
  7. maha
    maha avatar
    44 posts
    Member since:
    Jun 2010

    Posted 17 Aug 2010 Link to this post

    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.$);

     

  8. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 20 Aug 2010 Link to this post

    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
Back to Top