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

[Solved] treeview inside combobox selected value problem with objectdatasource

13 Answers 604 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Prabir
Top achievements
Rank 1
Prabir asked on 26 Apr 2008, 08:13 AM

I have a radtreeview inside radcombobox. My treeview is populated on demand. This combobox resides inside formview which is by default in edit mode. And i have an objectdatsource that contains the select and update mode.

The problem with my update mode is, the selected value of combox always becomes 0 it doesn't change even when using combo.set_value("something");
In client side the value changes but not in server side even when trackChanges() and commitChanges() is applied.

The following link contains the type of solution but its not working, with my q1 2008 415 version. it has a special parameter called <telerik:AjaxComboValueParameter />. Wouldn't it be better if that parameter would be provided by Telerik instead of trying to code it.
http://www.telerik.com/community/code-library/submission/b311D-ttdgm.aspx

Following is my javascript file for setting the value of the combobox when selecting a treenode. My objectdatasource update parameter contains <asp:ControlParameter Name="parentId" Type="Int32" ControlID="cbo" PropertyName="SelectedValue" />. The name of my radcombox inside formview edit mode is cbo and treeview is radPortalsTree.

function
radTreeViewPortalParent_OnClientNodeClicking(sender,eventArgs)

{

var comboBox=$find('<%=FormViewPortal.FindControl("cbo").ClientID%>');

var node=eventArgs.get_node();

var portalTree=$find('<%= radPortalsTree.ClientID %>');

if(portalTree.get_selectedNode().get_value()!=node.get_value())

{

comboBox.trackChanges();

comboBox.set_text(node.get_text());

comboBox.set_value(node.get_value());

var cboItem=comboBox.get_items().getItem(0);

cboItem.set_value(node.get_value());

comboBox.commitChanges();

}

comboBox.hideDropDown();

}

13 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 28 Apr 2008, 01:56 PM
Hi Prabir,

Welcome to Telerik Community!

I suggest that you follow this order in your NodeClicking event handler:

    comboBox.trackChanges(); 
     
    var cboItem=comboBox.get_items().getItem(0); 
    cboItem.set_value(node.get_text()); 
    comboBox.set_text(node.get_text()); 
     
    comboBox.commitChanges(); 

I hope this helps.

Regards,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Prabir
Top achievements
Rank 1
answered on 29 Apr 2008, 02:36 PM
The problem is the value gets changed in the client side which can be confirmed by the alert js function. But what about in the server side code when the Update link button in pressed in the formview edit mode? I still get the the parentId to be 0 all the time. I have tried PropertyName as SelectedValue as well as Value, nothing happens.

<asp:ObjectDataSource .......>
<UpdateParameters>
<asp:ControlParameter Name="parentId" Type="Int32" ControlID="radTreeViewPortalFormView" PropertyName="SelectedValue" />
....some more update parameters....
</UpdateParameters>
</ObjectDataSource>

Or could u send me a working Treeview populate on demand which is an item template in dropdown box and is inside a FormView in edit mode. 

Thankyou
0
Nikolay
Telerik team
answered on 01 May 2008, 02:03 PM
Hello Prabir,

I believe that the best way to proceed would be if you isolate the problem in a small and running project and attach the files to a new support thread. We will test your project locally and try to find a working solution for you.

Kind regards,
Nick
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Prabir
Top achievements
Rank 1
answered on 06 May 2008, 11:53 AM
I have uploaded my source file, in the following website
http://www.prabirshrestha.com/telerikProblem.zip
Could you please have a look at it.
Im using .net 3.5 and sql express and have not included the Telerik's .dll files. im using the radcontrols asp.net ajax 2008 q1.

How do i send the value of combobox to sqldatasource which is set from the client side using set_value().

note:
i have changed from objectdatasource to sqldatasource for easier code.
0
Prabir
Top achievements
Rank 1
answered on 06 May 2008, 05:17 PM
i was somehow able to fix the problem using sql datasource. the solution is to use            
<asp:ControlParameter Name="parentId" Type="Int32" ControlID="FormView1$cboParentId" PropertyName="SelectedValue" />

buy when i used the object datasource. it wouldn't change.
i have uploaded the problem with object datasource in the following website
http://www.prabirshrestha.com/telerikproblem2.zip
0
Prabir
Top achievements
Rank 1
answered on 06 May 2008, 05:20 PM
i was able to solve the problem using sqldatasource.
<UpdateParameters>
            <asp:Parameter Name="Name" />
            <asp:Parameter Name="id" Type="Int32" />
            <asp:ControlParameter Name="parentId" Type="Int32" ControlID="FormView1$cboParentId" PropertyName="SelectedValue" />
        </UpdateParameters>
but when i converted it to objectdatasource, i was not able to fix it. the update version of the website with object datasource has been uploaded to the following website.

http://www.prabirshrestha.com/telerikproblem2.zip

i would like the parent id of combobox to change when i click update in the formview.
0
Veselin Vasilev
Telerik team
answered on 09 May 2008, 11:07 AM
Hello Prabir,

I have changed the tvParentId_OnClientNodeClicking javascript function and now the ParentID is passed correctly:

function tvParentId_OnClientNodeClicking(sender,eventArgs) 
    var comboBox=$find('<%=FormView1.FindControl("cboParentId").ClientID%>'); 
    var node=eventArgs.get_node(); 
    var portalTree=$find('<%= tvMain.ClientID %>');                         
    if(portalTree.get_selectedNode().get_value()!=node.get_value()) 
    {            
        comboBox.trackChanges(); 
        var cboItem=comboBox.get_items().getItem(0);  
        cboItem.set_value(node.get_value());  
        comboBox.set_text(node.get_text());                          
        comboBox.commitChanges(); 
        comboBox.trackChanges(); 
        comboBox.set_value(node.get_value()); 
        comboBox.commitChanges(); 
    } 
    comboBox.hideDropDown(); 


Now if you put a breakpoint into the Update method you will notice that the parentID is correct, but the id is always 0. This is weird. Please try it and let me know how it goes.

Greetings,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Prabir
Top achievements
Rank 1
answered on 09 May 2008, 01:51 PM
hi,
somehow i have managed to fix up tvParentId_OnClientNodeClicking. My code has been changed and can be found in the following website http://www.prabirshrestha.com/telerikproblem3.zip
So now when i click the node, the update works properly.
But i ran up into a different problem.
When my formview is first loaded, the value of combobox is 0 and no treenodes are not  populated (they populate on demand). that means if i don't click any nodes in the tree and just click update, my parentid will be reseted to 0. how do i set the initial value of the combobox to the parentid which i can get from objectdatasource.
this doesn't seem to work inside javascript combobox.set_value('<%# Eval("parentId") %>'); (but <%= works inside javascript.)
basically i want to set the initial value to of the combobox which containts a treeviewinside. the treeview is populated on demand.
if u look at the code, supposei click a treeview at the left . for examplecategories>electronics>mobile. and click the update button in theformview, the parentId is always reseted to 0(that is if i don't select a node from treeview). so how to set the initial value of the combobox to the parentId? 
i cannot use combobox selectedvalue='<%# Bind("parentId") %>' because my nodes are populated on demand. 
The best solution would be to set the value on radcombobox OnClientLoad="cboParentId_OnClientLoad" but i have no idea how to get the value of objectdatasource from javascript.
0
Accepted
Veselin Vasilev
Telerik team
answered on 10 May 2008, 02:42 PM
Hi Prabir,

I have modified your files a bit and attached the project again.

Greetings,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Prabir
Top achievements
Rank 1
answered on 10 May 2008, 06:16 PM
Wow! that was something I never thought of, might be because of a bit different database table. That was pretty close to the solution anyways.

But actually my databasce table is a bit different. For simpicity I didn't put LineageName column (sorry for not informing you this earlier), which is auto calculated by using triggers.

For example for Mobile the LineageName would have the value /Electronics/Mobile/
for toshiba it would have /Electronics/Computer/Toshiba.

So i actually use <telerik:RadComboBox runat="server" ID="cboParentId" 
                Text='<%# Eval("LinageName") %>' ........> so the text of combobox is more user friendly then just putting the id, which the user might not find comfortable to workwith.

so i came up with a really wierd idea of putting ToolTip='<%#Eval("ParentId")%>' and then changing the follwing code 
function OnClientLoadHandler(sender, eventArgs)
{                    
    sender.trackChanges();
    var item = sender.get_items().getItem(0);
    item.set_value(sender.get_inputDomElement().title);
    sender.set_value(sender.get_inputDomElement().title);
    sender.commitChanges();
}

That means my tooltip contains the parentid, text contains the lineagename which is user friendly. so this accomplishes my task.
but i reallized that why not make the tooltip also user friendly so it also contains lienage name.
So the final solution: get the text from <asp:label ID="Label1" runat="server" Text='<%# Eval("ParentId") %>' /> which is already databound. (why wasn't i thinkin about this before? instead of again trying to databind the parenid to combobox.)
so my final javascript funciton looks as below:
function OnClientLoadHandler(sender, eventArgs)
{                    
    sender.trackChanges();
    var item = sender.get_items().getItem(0);
    var parentId=$get('<%=FormView1.FindControl("lblParentId").ClientID %>').innerText;
    item.set_value(parentId);
    sender.set_value(parentId);
    sender.commitChanges();
}
you might be wondering why innerText, thats because asp:label is rendered as span tags, so to get access to the Text propery of label use innerText so u can access inner text of span tags.
incase u want to use asp:hiddenfield might be in some other examples:
use the same code but modifiy it to be $get('......').value instead.

Thats the solution I had been trying to solve for almost a month, and now after getting support from telerik, its finally done.
Note: I will be deleting the telerikproblem zip files from my website(prabirshrestha.com) soon, because if anyone of you have the same problem you can download from the telerik post which was posted on  5/10/2008 9:42:26 AM. or from direct link below:
http://www.telerik.com/ClientsFiles/085057_telerikproblem3.zip
Please note that the changes i made in this current post is not updated on tat file, so please change according.

Thanks, Veskoni (from the Telerik team).
u guys rock
0
Veselin Vasilev
Telerik team
answered on 12 May 2008, 11:59 AM
Hi Prabir,

I am glad to hear that you have solved the problem.
Thank you for sharing your approach with the other members of the community. I am sure it will be helpful for someone.

Best wishes,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Prabir
Top achievements
Rank 1
answered on 12 May 2008, 02:39 PM
function tvParentId_OnClientNodeClicking(sender,eventArgs) 
    var comboBox=$find('<%=FormView1.FindControl("cboParentId").ClientID%>'); 
    var node=eventArgs.get_node(); 
    var portalTree=$find('<%= tvMain.ClientID %>');                         
    if(portalTree.get_selectedNode().get_value()!=node.get_value()) 
    {            
        comboBox.trackChanges(); 
        var cboItem=comboBox.get_items().getItem(0);  
        cboItem.set_value(node.get_value());  
        comboBox.set_text(node.get_text());                          
        comboBox.commitChanges(); 
        comboBox.trackChanges(); 
        comboBox.set_value(node.get_value()); 
        comboBox.commitChanges(); 
    } 
    comboBox.hideDropDown(); 

i didn't understand why you put trackchanges() and commitChanges() twice and even highlighted it. isn't one more than enough.
why twice? wouldn't it have funtion overhead and those stuffs...
wouldn't it be fine if it was called only once.
0
Veselin Vasilev
Telerik team
answered on 14 May 2008, 12:05 PM
Hi Prabir,

You are right, these two lines are not needed in this case.
Thanks for pointing that.

Greetings,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
ComboBox
Asked by
Prabir
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Prabir
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or