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

RadComboBox databind ondemand

1 Answer 277 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Marjan
Top achievements
Rank 1
Marjan asked on 07 Jul 2008, 07:37 AM

hi,
I try to implement custom control (inherit RadComboBox). For customize dropdownList I make the class for radcombobox.ItemTemplate. In this class in InstantiateIn method add some labels with DataBinding eventhandler.

I also set event ItemsRequested for data load ondemad:
void RadComboBox_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
{
int noItems = 15;

RadComboBox combo = (RadComboBox)o;
combo.DataSourceID =
null;
combo.DataSource =
null;
String sortExpression = this.Sort.SelectedValue;

// new datasource
ObjectDataSource ods = new ObjectDataSource("Artikli", "GetArtikliPagedSortedKlas");
// set parameters
ods.SelectParameters.Add("maximumRows", noItems.ToString());
ods.SelectParameters.Add(
"sortExpression", sortExpression);
//.... // there are more parameters. Those parameters must set at this point(depends from other controls)

combo.DataSource = ods;
combo.DataBind();
// There get the message InvalidOperationException ONLY IF PUT THE CONTROL IN FORMVIEW(on edit)
//Error message:"Databinding methods such as Eval(), XPath(), and Bind() can only be used in 
the context of a databound control."
}

 The new control works fine until I don't databind it. My case:put it on the FormView, databind and on run time choose edit(insert i did't try).

To summarize:

  1.  How to databind ondemad. In DropDownList header I have some extra controls on which values depends query to database.
  2. How to determine what is select for first time when user choose edit in FormView - to prepare a query which included rigt row.
  3. If in custom control add a new public property, put the control into FormView itemtemplate and bind any field get the error:(There was an error rendering the control. Cannot create an object of type 'System.Collections.Generic.List`1......) Set attribute [Bindable(false)] doesn't solve problem.

 The solution must be acteptable also for radgrid and gridview.

1 Answer, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 07 Jul 2008, 01:48 PM
Hi Marjan,

Please read this article for more detailed information about the problem.

Kind regards,
Simon
the Telerik team

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