Hello
I am developing a usercontrol using Radgrid. My problem is that when I insert a template column containing a RadAutoCompleteBox the insert command stops firing and the callback from the RadAutoCompleteBox inside the TemplateColumn is invalid. In Edit Mode everything works fine. If I remove the column from the grid the insert command starts firing again and works perfectly, any ideas as to what the problem might be?
the code for my custom column is as follows:
I create the grid on Page Load as described in the documentation.
Any help is highly appreciated
Best Regards,
Claus Veirup
I am developing a usercontrol using Radgrid. My problem is that when I insert a template column containing a RadAutoCompleteBox the insert command stops firing and the callback from the RadAutoCompleteBox inside the TemplateColumn is invalid. In Edit Mode everything works fine. If I remove the column from the grid the insert command starts firing again and works perfectly, any ideas as to what the problem might be?
the code for my custom column is as follows:
public class GridLookupColumn : GridTemplateColumn { private string _lookupDataMember; public string LookupDataMember { get { return _lookupDataMember; } set { _lookupDataMember = value; } } private string _lookupTextField; public string LookupTextField { get { return _lookupTextField; } set { _lookupTextField = value; } } private string _lookupValueField; public string LookupValueField { get { return _lookupValueField; } set { _lookupValueField = value; } } public class LookupActionTemplate : IBindableTemplate { public GridLookupColumn Column = null; public void InstantiateIn(Control container) { RadAutoCompleteBox lookup = new RadAutoCompleteBox(); lookup.ID ="LC" + this.Column.UniqueName; lookup.DataSource = Column.Owner.OwnerGrid.DataSource; lookup.DataMember = Column.LookupDataMember; lookup.DataTextField = Column.LookupTextField; lookup.DataValueField = Column.LookupValueField; lookup.EnableViewState = true; container.Controls.Add(lookup); lookup.DataBind(); lookup.DataBinding += new EventHandler(LookupDataBindingHandler); lookup.EntryAdded += new AutoCompleteEntryEventHandler(EntryAddedHandler); } private void EntryAddedHandler(object sender, EventArgs e) { RadAutoCompleteBox lookup = sender as RadAutoCompleteBox; if (lookup.Entries.Count > 1) { lookup.Entries.RemoveAt(0); ExtractValues(lookup.NamingContainer as GridDataItem); } } private void LookupDataBindingHandler(object sender, EventArgs e) { RadAutoCompleteBox lookup = sender as RadAutoCompleteBox; GridDataItem item = (GridDataItem)lookup.NamingContainer; string id = DataBinder.Eval(item.DataItem, this.Column.DataField).ToString(); string text = String.Empty; DataSet data = (DataSet)Column.Owner.DataSource; foreach (DataRow r in data.Tables[Column.LookupDataMember].Rows) { if (r[Column.LookupValueField].ToString() == id) { text = r[Column.LookupTextField].ToString(); } } AutoCompleteBoxEntry entry = new AutoCompleteBoxEntry(text, id); if(text != String.Empty) lookup.Entries.Add(entry); } public System.Collections.Specialized.IOrderedDictionary ExtractValues(Control container) { IOrderedDictionary values = new OrderedDictionary(); RadAutoCompleteBox lookup = container.FindControl("LC" + Column.UniqueName) as RadAutoCompleteBox; values.Add(Column.UniqueName, lookup.Entries[0].Value); return values; } } public class LookupTemplate : ITemplate { public GridLookupColumn Column = null; public void InstantiateIn(Control container) { Label l = new Label(); l.ID = Column.UniqueName; container.Controls.Add(l); l.DataBinding += new EventHandler(LookupDataBindingHandler); } private void LookupDataBindingHandler(object sender, EventArgs e) { Label l = sender as Label; GridDataItem item = (GridDataItem)l.NamingContainer; string id = DataBinder.Eval(item.DataItem, this.Column.DataField).ToString(); DataSet data = (DataSet) Column.Owner.DataSource; foreach (DataRow r in data.Tables[Column.LookupDataMember].Rows) { if (r[Column.LookupValueField].ToString() == id) { l.Text = r[Column.LookupTextField].ToString(); } } } } public GridLookupColumn() { LookupActionTemplate lookupActionTemplate = new LookupActionTemplate(); LookupTemplate lookupTemplate = new LookupTemplate(); lookupTemplate.Column = this; lookupActionTemplate.Column = this; this.EditItemTemplate = lookupActionTemplate; this.ItemTemplate = lookupTemplate; this.InsertItemTemplate = lookupActionTemplate; } }I create the grid on Page Load as described in the documentation.
Any help is highly appreciated
Best Regards,
Claus Veirup