Client Script to set_value

4 posts, 0 answers
  1. Andy Ho
    Andy Ho avatar
    41 posts
    Member since:
    May 2010

    Posted 27 Feb 2011 Link to this post

    Hi,

    I added a RadCombobox to a page with Datasource pointed to a LINQDataSource. Then I add a Javascript to set its value on load:

    <script type="text/javascript">
           var combox = $find("<%=dfDocuments.clientID %>");
           combox.set_value('3');
       </script>

    It works fine, but then I add the following code to add a blank line to the Combobox:

    Protected Sub dfDocuments_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles dfDocuments.DataBound
            Dim li As New RadComboBoxItem
            li.Value = "0"
            li.Text = "--Select--"
            li.Selected = False
            dfDocuments.Items.Insert(0, li)
        End Sub

    Then the set_value script doesn't works anymore.

    Any advice? Thanks.

    Andy
  2. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 03 Mar 2011 Link to this post

    Hi Andy Ho,

    I tried to create a sample page and reproduce the issue using the code snippet provided here - but without success.
    Could you please paste here a working code that fully illustrates your implementation?
    Thank you in advance.


    Best wishes,
    Kalina
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. Andy Ho
    Andy Ho avatar
    41 posts
    Member since:
    May 2010

    Posted 06 Mar 2011 Link to this post

    Kalina,

     

    <body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager 
    ID="RadScriptManager1" runat="server"> 
    </telerik:RadScriptManager>
    <telerik:RadComboBox 
    ID="dfDocuments" runat="server" DataSourceID="ldsDocuments"                    
    DataTextField="Subject" DataValueField="FileID" Width="250px">                
    </telerik:RadComboBox>
    <asp:LinqDataSource ID="ldsDocuments" runat="server"  ContextTypeName="dcLAPDataContext"        
    OrderBy="PageID" Select="new (FileID, Subject)" TableName="LAP_Files"></asp:LinqDataSource>
    </form>
    <script type="text/javascript">       
    // Tried to set the defalut value to 3 with Javascript
    var 
    combox = $find("<%=dfDocuments.clientID%>");            
    combox.set_value('3');    
    </script>
    </body></html>

    My VB Code:

    Partial Class Testing_ComboText
       Inherits 
    System.Web.UI.Page

    Protected Sub dfDocuments_DataBound(ByVal sender As 
    Object, ByVal e As System.EventArgs) Handles  dfDocuments.DataBound
           Dim li As 
    New RadComboBoxItem
            li.Value = 
    "0"
            li.Text =
    "--Select--"
            li.Selected =  F
    alse
            'If I remark 
    the line below, the Javascript works ok, otherwise failed
            dfDocuments.Items.Insert(0,
    li)
    End Sub
    End Class
  4. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 08 Mar 2011 Link to this post

    Hello Andy Ho,

    As I understand, you are trying to preselect an item in the RadComboBox.
    Let me suggest you handle the OnClientLoad event or the RadComboBox in this way.
    <telerik:RadComboBox runat="server" ID="dfDocuments"
    DataSourceID="ldsDocuments" OnClientLoad="OnClientLoad"    
    ...

    <script type="text/javascript">
     
    function OnClientLoad(sender)
    {
        var item = sender.findItemByValue('3');
        item.select();
    }
    </script>

    Kind regards,
    Kalina
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Back to Top