
Jayant Paliwal
Top achievements
Rank 1
Jayant Paliwal
asked on 14 Oct 2009, 04:59 PM
Hii,
I have a treeview control inside a combobox. The treeview is binding with datasource and I set its DataTextField,DataFieldParentID and DataValueField property. By this user can select any node of that treeview control and during insert query I get the value of the selected item by below code.
Now my problem is in the edit mode of data, I need to set the combobox value that comes from query string. Like
RadComboBox1 is populating with blank rather then expected text.
This code only works if I dont use treeview inside a combobox. Please help me what I am missing here.
Thanks,
Jayant Paliwal
I have a treeview control inside a combobox. The treeview is binding with datasource and I set its DataTextField,DataFieldParentID and DataValueField property. By this user can select any node of that treeview control and during insert query I get the value of the selected item by below code.
RadTreeView treeBusiness = (RadTreeView)this.RadComboBox1.Items[0].FindControl("RadTreeView1"); |
int id =Convert.ToInt32(treeBusiness.SelectedValue); |
Now my problem is in the edit mode of data, I need to set the combobox value that comes from query string. Like
RadComboBox1.SelectedValue = Request.QueryString["ID"]; |
RadComboBox1 is populating with blank rather then expected text.
This code only works if I dont use treeview inside a combobox. Please help me what I am missing here.
Thanks,
Jayant Paliwal
7 Answers, 1 is accepted
0

Vesko
Top achievements
Rank 2
answered on 16 Oct 2009, 07:56 AM
You can try the following:
RadComboBox1.Items[0].Value = Request.QueryString["ID"]; |
RadComboBox1.Items[0].Selected = true; |
0

Jayant Paliwal
Top achievements
Rank 1
answered on 16 Oct 2009, 05:15 PM
Hii Sean,
Thanks for you reply. I tried your sol. but it is not working for me.
Thanks for you reply. I tried your sol. but it is not working for me.
0

Vesko
Top achievements
Rank 2
answered on 20 Oct 2009, 11:57 AM
What happens?
Maybe you need to set the Text of Items[0] as well.
Maybe you need to set the Text of Items[0] as well.
0

Jayant Paliwal
Top achievements
Rank 1
answered on 23 Oct 2009, 09:14 PM
Hii Sean,
Yes, by setting Text property it is showing the value on combobox, but it is not solving my problem. I want to get the value of that combobox on button click.
// Calling this function on page load event (!IsPostBack) condition
private void LoadItemGroups()
{
DataSet ds = dwdb.ExecuteDataSet("sp_getItemGroupsList");
//find the treeview
RadTreeView tree = (RadTreeView)this.RadComboBox1.Items[0].FindControl("RadTreeView1");
tree.DataSource = ds;
tree.DataBind();
RadComboBox1.Items[0].Value = "2";
RadComboBox1.Items[0].Selected = true;
RadComboBox1.Items[0].Text = "Customer1";
}
// Now on button click I want to get the selected value of combo.
protected void Button1_Click(object sender, EventArgs e)
{
RadTreeView tree = (RadTreeView)this.RadComboBox1.Items[0].FindControl("RadTreeView1");
string strID = tree.SelectedValue;
// In strID i am getting blank value instead of value 2.
string strID2 = RadComboBox1.SelectedValue;
// Here combo always giving value that was set by LoadItemGroups() and if I select another value from that tree control, and after clicking the button tree.SelectedValue; is giving the correct value but RadComboBox1.SelectedValue; always giving the old value (I.E. 2), also combo showing the first text "Customer1" that was set by LoadItemGroups() function, instead of showing the newly selected text.
}
Thanks,
Jayant Paliwal
Yes, by setting Text property it is showing the value on combobox, but it is not solving my problem. I want to get the value of that combobox on button click.
// Calling this function on page load event (!IsPostBack) condition
private void LoadItemGroups()
{
DataSet ds = dwdb.ExecuteDataSet("sp_getItemGroupsList");
//find the treeview
RadTreeView tree = (RadTreeView)this.RadComboBox1.Items[0].FindControl("RadTreeView1");
tree.DataSource = ds;
tree.DataBind();
RadComboBox1.Items[0].Value = "2";
RadComboBox1.Items[0].Selected = true;
RadComboBox1.Items[0].Text = "Customer1";
}
// Now on button click I want to get the selected value of combo.
protected void Button1_Click(object sender, EventArgs e)
{
RadTreeView tree = (RadTreeView)this.RadComboBox1.Items[0].FindControl("RadTreeView1");
string strID = tree.SelectedValue;
// In strID i am getting blank value instead of value 2.
string strID2 = RadComboBox1.SelectedValue;
// Here combo always giving value that was set by LoadItemGroups() and if I select another value from that tree control, and after clicking the button tree.SelectedValue; is giving the correct value but RadComboBox1.SelectedValue; always giving the old value (I.E. 2), also combo showing the first text "Customer1" that was set by LoadItemGroups() function, instead of showing the newly selected text.
}
Thanks,
Jayant Paliwal
0

Vesko
Top achievements
Rank 2
answered on 28 Oct 2009, 10:24 AM
In OnClientNodeClicked event of the treeview you should set the text and the value of the combobox's item:
Note the usage of the trackChanges and commitChanges methods.
Hope this helps.
combo.trackChanges(); |
var item = combo.get_items().getItem(0); |
item.set_text(node.get_text()); |
item.set_value(node.get_value()); |
combo.commitChanges(); |
Note the usage of the trackChanges and commitChanges methods.
Hope this helps.
0

Jayant Paliwal
Top achievements
Rank 1
answered on 30 Oct 2009, 04:54 PM
Hii Sean,
I tried your new solution but still it is not satisfiying me completely. Still when I click on button to get newly selected value, it gives me the new value but combox again reset with old text. I am pasting the complete code what I am using.
I checked it with OnClientNodeClicking event too, but not working.
Here is the C# code
Can you please check this code and let me know what I am missing ?
Thanks,
Jayant Paliwal
I tried your new solution but still it is not satisfiying me completely. Still when I click on button to get newly selected value, it gives me the new value but combox again reset with old text. I am pasting the complete code what I am using.
<form id="form1" runat="server"> |
<div> |
<asp:ScriptManager ID="ScriptManager1" runat="server"> |
</asp:ScriptManager> |
<telerik:RadComboBox ID="RadComboBox1" runat="server" Width="200px" Height="300px" OnClientDropDownOpened="OnClientDropDownOpenedHandler" > |
<ItemTemplate> |
<div onclick="StopPropagation(event)"> |
<telerik:RadTreeView ID="RadTreeView1" runat="server" DataFieldID="ItemGroupID" DataFieldParentID="ParentItemGroupID" |
DataTextField="ItemGroup" DataValueField="ItemGroupID" OnClientNodeClicked="nodeClicking"> |
</telerik:RadTreeView> |
</div> |
</ItemTemplate> |
<Items> |
<telerik:RadComboBoxItem /> |
</Items> |
</telerik:RadComboBox> |
</div> |
<script type="text/javascript"> |
function nodeClicking(sender, args) { |
var comboBox = $find("<%= RadComboBox1.ClientID %>"); |
var node = args.get_node(); |
comboBox.trackChanges(); |
comboBox.set_text(node.get_text()); |
comboBox.get_items().getItem(0).set_value(node.get_value()); |
comboBox.commitChanges(); |
comboBox.hideDropDown(); |
} |
function StopPropagation(e) { |
if (!e) { |
e = window.event; |
} |
e.cancelBubble = true; |
} |
function OnClientDropDownOpenedHandler(sender, eventArgs) { |
var tree = sender.get_items().getItem(0).findControl("RadTreeView1"); |
var selectedNode = tree.get_selectedNode(); |
if (selectedNode) { |
selectedNode.scrollIntoView(); |
} |
} |
</script> |
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> |
</form> |
Here is the C# code
protected void Page_Load(object sender, EventArgs e) |
{ |
if (!IsPostBack) |
{ |
LoadItemGroups(); |
} |
} |
private void LoadItemGroups() |
{ |
DataSet ds = dwdb.ExecuteDataSet("sp_getItemGroupsList"); |
ItemGroups iG = new ItemGroups(); |
//find the treeview |
RadTreeView tree = (RadTreeView)this.RadComboBox1.Items[0].FindControl("RadTreeView1"); |
tree.DataSource = ds; |
tree.DataBind(); |
RadComboBox1.Items[0].Value = "25"; |
RadComboBox1.Items[0].Selected = true; |
RadComboBox1.Items[0].Text = "CV/Met"; |
} |
protected void Button1_Click(object sender, EventArgs e) |
{ |
RadTreeView tree = (RadTreeView)this.RadComboBox1.Items[0].FindControl("RadTreeView1"); |
string strTreeID = tree.SelectedValue; |
string strComboID = RadComboBox1.SelectedValue; |
} |
Can you please check this code and let me know what I am missing ?
Thanks,
Jayant Paliwal
0

Basel Nimer
Top achievements
Rank 2
answered on 20 May 2010, 03:14 AM
even late, but this might benefit someone else.
see the end of this post
http://www.telerik.com/community/forums/aspnet-ajax/combobox/set-the-value-of-combo-box.aspx#1205727
see the end of this post
http://www.telerik.com/community/forums/aspnet-ajax/combobox/set-the-value-of-combo-box.aspx#1205727