Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
640
CheckBoxProvider for TemplateDataField
posted

Hello,

I'm trying to add CheckBoxProvider to my custom TemplateDataField and cannot make checkbox apear on double click.

Is this a correct way of adding CheckBoxProvider for TemplateDataField?

Assume grid is created and added to page, EditBehavior added and enabled, CellEditingBehavior added and enabled, other fields in the same grid (with TextEditorProvider or NumericEditorProvider for ex.) are editable on double click

---------------------------------------------------

col = new TemplateDataField
{
    ItemTemplate = new CheckBoxTemplate(),
    Type = typeof(bool),
    Key = "ColumnName"  
};

grid.Columns.Add(col);

var provider = new CheckBoxProvider("ProviderForColumn");
grid.EditorProviders.Add(provider);
grid.Behaviors.EditingCore.Behaviors.CellEditing.ColumnSettings.Add(new EditingColumnSetting { ColumnKey = col.Key, EditorID = provider.ID});
---------------------------------------------------

CheckBoxTemplate is extremly simple: just one image on true and another on false (below)

---------------------------------------------------

    public class CheckBoxTemplate: ITemplate, INamingContainer
    {
        public string CheckedImageUrl;
        public string NotCheckedImageUrl;
        public string ValueFieldName;

        public void InstantiateIn(Control c)
        {
            if (String.IsNullOrEmpty(this.ValueFieldName) && (c is Infragistics.Web.UI.TemplateContainer))
            {
                GridRecordItem item = (GridRecordItem)((Infragistics.Web.UI.TemplateContainer)c).Item;
                this.ValueFieldName = item.Column.Key;
            }

            HtmlImage img = new HtmlImage();
            img.DataBinding += OnDisplayDataBinding;
            c.Controls.Add(img);
        }

        void OnDisplayDataBinding(object sender, EventArgs e)
        {
            HtmlImage img = (HtmlImage)sender;

            object dataItem = (img.NamingContainer is IDataItemContainer) ?
                ((IDataItemContainer)img.NamingContainer).DataItem :
                ((Infragistics.Web.UI.TemplateContainer)img.NamingContainer).DataItem;

            object dataValue = DataBinder.GetPropertyValue(dataItem, this.ValueFieldName);

            if (dataValue is bool)
                img.Src = (bool)dataValue ? CheckedImageUrl : NotCheckedImageUrl;
        }
    }

---------------------------------------------------

 

I'm using 10.3.20103.2217 version of controls and cannot move to ASP.NET 4.0 now. I cannot use declarative syntax as do not know what to add at compile time and have to add columns dynamically.

 

Any help appreciated.