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:
- How to databind ondemad. In DropDownList header I have some extra controls on which values depends query to database.
- How to determine what is select for first time when user choose edit in FormView - to prepare a query which included rigt row.
- 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.