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.

Parents Reply
  • 640
    posted in reply to Georgi Georgiev

    Hello, Georgi

    Sample attached  please set path to cust.xml here

    ds.ReadXml("c:\\cust.xml", XmlReadMode.ReadSchema); (line 130 in LastUpdatable.aspx.cs)

    according your local environment.

    To reproduce:

    1 - Open LastUpdatable.aspx in your browser

    2 - Press Edit button to switch grid into edit mode

    3 - Edit values in Address1 column for example. See values save changed state when you edit it and switch to another cell

    4 - Press Save Changes and see (using debugger) grid1_RowUpdating is called correctly and entered values are passed to server.

    5 - Refresh page, press Edit button do not edit other columns except first one.

    6 - Try to edit First column (called "Flag"). Double click on false value and see unchecked Checkbox, double click on true value and also see unchecked checkbox.

    7 - Check any checkbox and see checkboxes for all rows are checked now

    8 - Press Save Changes and notice grid1_RowUpdating is not called (use debugger to see this)

    Question is: How can I add checkbox editor for boolean field in WebDataGrid and get grid1_RowUpdating called with correct checkx state passed to server?

     

    Regards,
    Andrey

Children
No Data