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

[Solved] Rebind RadComboBoxes

8 Answers 535 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Alan
Top achievements
Rank 1
Alan asked on 08 Mar 2008, 06:31 PM
I would like to rebind bound RadComboBoxes when insertions or deletions have occurred, however I get this error:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. 

A typical RadComboBox declaration
                                <telerik:RadComboBox  
                                    ID="cmbCity" 
                                    runat="server" 
                                    DataSourceID="srcAllCity" 
                                    CssClass="rowtbxedit" 
                                    RadComboBoxImagePosition="Right" 
                                    Width="200px" 
                                    DataTextField="City" 
                                    DataValueField="City" 
                                    Skin="Office2007" 
                                    ShowDropDownOnTextboxClick="False"   
                                    text='<%# Bind("City") %>' 
                                    AllowCustomtext="false" 
                                    MarkFirstMatch="true" 
                                > 
                                    <CollapseAnimation type="OutQuint" duration="200"></CollapseAnimation> 
                                    <ExpandAnimation type="OutQuart"></ExpandAnimation> 
                                </telerik:RadComboBox> 

                <asp:SqlDataSource  
                    id="srcAllCity" 
                    SelectCommand="SELECT City FROM qryAllCities ORDER BY City"   
                    ConnectionString="<%$ ConnectionStrings:RentalSQL %>"   
                    runat="server" 
                 /> 
 
 

since this doesn't work, how do I get the comboboxes to repopulate? 

8 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 11 Mar 2008, 09:20 AM
Hi Alan,

Is your combo placed in a grid? If so, I suggest you take a look at this example: Combo in grid

If not - I suggest that you set a static text in the Text property of the combobox.

About re-binding the combo - Just call the DataBind() method of the combobox after deleting or inserting a new item in the database. I have attached a simple project demonstrating this.

Sincerely yours,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Alan
Top achievements
Rank 1
answered on 11 Mar 2008, 01:31 PM
I viewed your zipped project and have a question.  Does it matter whether the DataSourceID is supplied declaritively or in programming?  I have specified the DataSourceID in the aspx file when declaring the combobox. 

I am doing the .DataBind() in a similar manner to what you have but I get the error I described in the earlier post.
0
Veselin Vasilev
Telerik team
answered on 14 Mar 2008, 08:05 AM
Hi Alan,

No, it does not matter either the DataSourceID is set inline or in the code behind.

Since you are still getting an error - please isolate the problem in a small project and send it to us via a new support ticket. So, we can test it and find a working solution for you.

Greetings,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Alan
Top achievements
Rank 1
answered on 14 Mar 2008, 02:45 PM
I did some further investigating and found that the problem occurs when I have a RADComboBox whose list is bound to a data source and whose text attribute is bound to a column in another Linq To SQL data source via bind().  It's the bind() that is throwing the error.
0
Rosi
Telerik team
answered on 18 Mar 2008, 05:55 PM
Hi Alan,

This is the expected behavior as RadComboBox needs the datasource of its parent to bind the Text property. I suggest that you  call DataBind() method of the parent control of RadComboBox instead of its own.

You can see the attached project for more reference. Clicking the button will rebind the data view control

Hope this helps.


Best wishes,
Rosi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Alan
Top achievements
Rank 1
answered on 18 Mar 2008, 09:31 PM
This solution doesn't make a lot of sense to me.  I want to rebind the list portion of the combobox because the list items in the db have changed.  I do not need to rebind the text attribute of the combobox, but this is also occuring when I call the databind method of the combobox.  Shouldn't the combobox databind() only rebind the list items?
0
Veselin Vasilev
Telerik team
answered on 21 Mar 2008, 04:17 PM
Hello Alan,

I believe the best way to proceed is to send us a sample project demonstrating the problem. Please include what is the expected result and what is the actual one.

Thanks

Kind regards,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Veselin Vasilev
Telerik team
answered on 24 Mar 2008, 03:53 PM
Hi Alan,

I tried to run the project you sent, but I keep getting this error:

Invalid object name 'tblAgent'.


Regardless of this, this is the expected behavior of the combobox. You can try to replace the combobox with the standard dropdown list and you will get the same result. All you need to do is to remove the 

text

='<%# Bind("City") %>'

from the aspx file. You can set the Text of the combobox in the DataBound event handler:

Protected Sub RadComboBox1_DataBound(ByVal sender As ObjectByVal e As EventArgs) Handles RadComboBox1.DataBound  
    (DirectCast(sender, RadComboBox)).Text = "test" 
End Sub 


Greetings,
Veskoni
the Telerik team

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