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

set the value of combo box

14 Answers 338 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Lubna Ansari
Top achievements
Rank 1
Lubna Ansari asked on 30 Mar 2010, 03:06 PM
Hi,
Initially i am binding the dropdown control.
After that based on selection of grid value , i want to set the value of combo box.
How to set selected value at run time ?

I've tried following but it is not working

function

 

RowSelected(sender, args)

 

{

 

var combo = <%=cmbCondQn.ClientID %>;

 

 

var value = args.getDataKeyValue("Question");

 

combo.FindItemByText(value).Selected =

true;

 

 

 

 

}

Below is my grid code

 

<

 

telerik:RadGrid ID="RadGrid1"

 

 

Width="97%" AllowSorting="True" PageSize="15" AllowPaging="True" runat="server" AllowAutomaticDeletes="True"

 

 

Gridlines="None" DataSourceID="dsConditionalQuestion" OnItemDataBound="RadGrid1_ItemDataBound" OnItemDeleted="RadGrid1_ItemDeleted"><%--OnRowCommand="RadGrid1_RowCommand" OnRowDataBound="RadGrid1_RowDataBound" OnRowDeleted="RadGrid1_RowDeleted" OnRowDeleting="GridView1_RowDeleting"--%>

 

 

<MasterTableView Width="100%" AutoGenerateColumns="false" DataSourceID="dsConditionalQuestion" DataKeyNames="ID"

 

 

ClientDataKeyNames="Question,Answer,Action,Dependent_QuestionID" >

 

<

 

ClientSettings>

 

 

<Selecting AllowRowSelect="true" />

 

 

<ClientEvents OnRowSelected="RowSelected" />

 

 

</ClientSettings>

 

 

</telerik:RadGrid>

Regards,
Lubna.

 

14 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 30 Mar 2010, 03:17 PM
Hello Lubna Ansari,

Please try using the Select method of the Item, i.e.
combo.FindItemByText(value).Select()

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
Lubna Ansari
Top achievements
Rank 1
answered on 30 Mar 2010, 03:33 PM
Hi Simon,

Thanks for the reply.
But it is giving error "Object doesnot support this property or method."
Here is my combobox declaration

<

 

telerik:RadComboBox ID="cmbCondQn" runat="server" DataSourceID="dsQuestion"

 

 

DataTextField="Question" DataValueField="ID" OnSelectedIndexChanged="cmbCondQn_OnSelectedIndexChanged"

 

 

AutoPostBack="true"></telerik:RadComboBox>

Below is my javascript. I am getting correct values in alert but it is giving error when I set the combobox value.

 

function

 

RowSelected(sender, args)

 

{

 

var combo = <%=cmbCondQn.ClientID %>;

 

alert(combo);

 

var value = args.getDataKeyValue("Question");

 

alert(value);

combo.FindItemByText(value).Select();

}

Regards,
Lubna.

0
Simon
Telerik team
answered on 30 Mar 2010, 03:53 PM
Hello Lubna Ansari,

The client-side API differs between the classic version of RadComboBox and its ASP.NET AJAX counterpart. It is possible that you are using the wrong API.

Can you please let me know the version of RadComboBox that you are using?

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
Lubna Ansari
Top achievements
Rank 1
answered on 30 Mar 2010, 04:00 PM
Hi Simon,

I'm using Telerik 2009.3.1314.35
0
Accepted
Simon
Telerik team
answered on 30 Mar 2010, 06:23 PM
Hello Lubna Ansari,

Thank you for confirming that.

In this case you need to use the API of RadComboBox for ASP.NET AJAX. Your code then will look in this way:
RowSelected(sender, args)
{
 
var combo = $find("<%=cmbCondQn.ClientID %>");
  
alert(combo);
  
var value = args.getDataKeyValue("Question");
  
alert(value);
combo.findItemByText(value).select();
}

Best wishes,
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
Lubna Ansari
Top achievements
Rank 1
answered on 31 Mar 2010, 10:40 AM
Hi Simon,

Many thanks for the solution.

I was just trying to set the combo box with value field by replacing

findItemByText with findItemByValue

 but it is not working. Below is my code.

var

 

combo = $find("<%=cmbDepQn.ClientID %>");

 

value = args.getDataKeyValue(

"Dependent_QuestionID");

 

combo.findItemByValue(value).select();


<

 

telerik:RadComboBox ID="cmbDepQn" runat="server" DataSourceID="dsQuestion" DataTextField="Question"

 

 

DataValueField="ID"></telerik:RadComboBox>

Regards,
Lubna.

 

0
Lubna Ansari
Top achievements
Rank 1
answered on 31 Mar 2010, 10:43 AM
pls discard the last post

combo.findItemByValue(value).select(); is working fine :))

0
Basel Nimer
Top achievements
Rank 2
answered on 31 Mar 2010, 02:14 PM
Hello,

I have almost the same case, but i have a tree inside the combobox (both are telerik), in the ComboTreeNodeClicking event, i set the text and the value of the combo box using the following JS code

            combo.set_text(node.get_text()); 
            combo.set_value(node.get_value()); 
returning to code behind, i find that the combo text was set correctly, but i cannot find the value!!!!

any suggestions?

0
Simon
Telerik team
answered on 31 Mar 2010, 04:19 PM
Hello Basel Nimer,

In this case the Value is automatically re-set after postback as the RadComboBox cannot find an Item matching its input's text.

You can store the value of the Node as the Value of the only RadComboBoxItem, i.e.

combo.trackChanges();
combo.get_items().getItem(0).set_value(node.get_value());
combo.commitChanges();

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
Basel Nimer
Top achievements
Rank 2
answered on 20 May 2010, 03:11 AM
Logic.

one more question, How to get a reference to the parent combo from the nodeclicking event?
0
Basel Nimer
Top achievements
Rank 2
answered on 20 May 2010, 03:24 AM
Found something here:
http://www.telerik.com/community/forums/aspnet-ajax/treeview/radtreeview-reference-to-parent-radcombobox.aspx

it works, but it might get buggy, imagine the combo box (or any control in the hierarchy) starts with an "i"!!

anyhow, i will use it.

P.S. cannot this be in the Client APIs of the treeview? actually, i am thinking of a built in Combobox with a treeview. nice to have in telerik.

might do it myself :D
 



0
Simon
Telerik team
answered on 20 May 2010, 03:10 PM
Hello Basel Nimer,

Another way would be to set the ClientID of the RadComboBox as a custom attribute to the RadTreeView, e.g.
treeView.Attributes.Add("parentComboBoxId", comboBox.ClientID);

Then, on the client, in the NodeClicking event of the RTV you can get this attribute and use it with the $find function to get the client-side RCB reference, e.g.
var parentComboBoxId = sender.get_attributes().getAttribute("parentComboBoxId");
var comboBox = $find(parentComboBoxId);

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
Basel Nimer
Top achievements
Rank 2
answered on 20 May 2010, 03:28 PM
well, i was using this, but in the current scenario (the treecombo is in a dynamically loaded control) if i refer to ClientID , i get an ajax error.

i dont know why. and i tried to separate it in one application to send it to you but it was too complex.


0
Simon
Telerik team
answered on 28 May 2010, 01:19 PM
Hello Basel Nimer,

What is the error you are receiving?

As an alternative you can try another approach: handle the client-side Load event of the RadComboBox and set a global variable to the control's object.
var parentComboBox;
 
function onLoad(sender) {
    parentComboBox = sender;
}
 
function onNodeClicking(sender, eventArgs) {
//    parentComboBox
}

Later in the RadTreeView event handlers you can use the global variable to reference the RCB.

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
Lubna Ansari
Top achievements
Rank 1
Answers by
Simon
Telerik team
Lubna Ansari
Top achievements
Rank 1
Basel Nimer
Top achievements
Rank 2
Share this question
or