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

Client Script to set_value

3 Answers 196 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Andy Ho
Top achievements
Rank 1
Andy Ho asked on 28 Feb 2011, 04:48 AM
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

3 Answers, 1 is accepted

Sort by
0
Kalina
Telerik team
answered on 03 Mar 2011, 07:23 PM
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!
0
Andy Ho
Top achievements
Rank 1
answered on 07 Mar 2011, 02:20 AM
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
0
Kalina
Telerik team
answered on 08 Mar 2011, 01:33 PM
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!
Tags
ComboBox
Asked by
Andy Ho
Top achievements
Rank 1
Answers by
Kalina
Telerik team
Andy Ho
Top achievements
Rank 1
Share this question
or