Support For mapping to Objects

Last post 09-02-2008 10:29 AM by sonu. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 09-01-2008 4:01 PM

    • shrockas
    • Top 500 Contributor
    • Joined on 09-01-2008
    • Wannabe Slacker
    • Points 70

    Support For mapping to Objects

    I am using your data controls with LINQ to SQL classes, and I do not seem to be able to use mulitpart data field names. For example say i am displaying orders so the list passed to the data grid is of type order. I want to display the customers id in the grid LINQ to SQL allows me to get to it by customer.id I can link to anything in the orders table itself using the control as is, but i cannot get to the data in foreign key tables that LINQ to SQL exposes.

  •  Advertisement

    Outstanding performance. Full ASP.NET AJAX support. Nearly codeless development.

     
  • 09-01-2008 4:36 PM In reply to

    • shrockas
    • Top 500 Contributor
    • Joined on 09-01-2008
    • Wannabe Slacker
    • Points 70

    Re: Support For mapping to Objects

    I hacked the functionality into the base GridViewBoundColumn.js and GridViewBoundColumn.debug.js...

    I will paste in the change here... I would be glad to hack up the rest of the subtypes of bound column and submit them... but I would like you guys to take a look first and see if there is a better way to get where I am going.

    I just had to make a small change to the first if statement in renderData

    Look for /* Begin my edits */ there is a corresponding /* End my edits */ when I am finished

    Type.registerNamespace('AjaxDataControls');

    $ADC.GridViewBoundColumn = function()
    {
        /// <summary>
        /// Represents a column that is displayed as text in a GridView control.
        /// </summary>
       
        this._applyFormatInEditMode = false;
        this._dataField = '';
        this._dataFormatString = '';
        this._nullDisplayText = '';
        this._readOnly = false;

        $ADC.GridViewBoundColumn.initializeBase(this);
    }

    $ADC.GridViewBoundColumn.prototype =
    {
        get_applyFormatInEditMode: function() {
            /// <value type="Boolean">
            /// Whether the formatting string specified by the DataFormatString property is applied to field values when the GridView control that contains the GridViewBoundColumn object is in edit mode.
            /// </value>
            if (arguments.length !== 0) throw Error.parameterCount();

            return this._applyFormatInEditMode;
        },

        set_applyFormatInEditMode: function(value) {
            var e = Function._validateParams(arguments, [{ name: 'value', type: Boolean}]);
            if (e) throw e;

            if (this._applyFormatInEditMode != value) {
                this._applyFormatInEditMode = value;
                this.raisePropertyChanged('applyFormatInEditMode');
            }
        },

        get_dataField: function() {
            /// <value type="String">
            /// Use this property to specify the name of the data field to bind with this column.
            /// </value>
            if (arguments.length !== 0) throw Error.parameterCount();

            return this._dataField;
        },

        set_dataField: function(value) {
            var e = Function._validateParams(arguments, [{ name: 'value', type: String}]);
            if (e) throw e;

            if (this._dataField != value) {
                this._dataField = value;
                this.raisePropertyChanged('dataField');
            }
        },

        get_dataFormatString: function() {
            /// <value type="String">
            /// Use the <b>DataFormatString</b> property to specify a custom display format for the values displayed in the GridViewBoundColumn object. If the DataFormatString property is not set, the field's value is displayed without any special formatting.
            /// </value>
            if (arguments.length !== 0) throw Error.parameterCount();

            return this._dataFormatString;
        },

        set_dataFormatString: function(value) {
            var e = Function._validateParams(arguments, [{ name: 'value', type: String}]);
            if (e) throw e;

            if (this._dataFormatString != value) {
                this._dataFormatString = value;
                this.raisePropertyChanged('dataFormatString');
            }
        },

        get_nullDisplayText: function() {
            /// <value type="String">
            /// Use this property to specify a custom caption to display for fields that have a null value. If this property is not set, null field values are displayed as empty strings ("").
            /// </value>
            if (arguments.length !== 0) throw Error.parameterCount();

            return this._nullDisplayText;
        },

        set_nullDisplayText: function(value) {
            var e = Function._validateParams(arguments, [{ name: 'value', type: String}]);
            if (e) throw e;

            if (this._nullDisplayText != value) {
                this._nullDisplayText = value;
                this.raisePropertyChanged('nullDisplayText');
            }
        },

        get_readOnly: function() {
            /// <value type="Boolean">
            /// Whether the value of the field can be modified in edit mode.
            /// </value>
            if (arguments.length !== 0) throw Error.parameterCount();

            return this._readOnly;
        },

        set_readOnly: function(value) {
            var e = Function._validateParams(arguments, [{ name: 'value', type: Boolean}]);
            if (e) throw e;

            if (this._readOnly != value) {
                this._readOnly = value;
                this.raisePropertyChanged('readOnly');
            }
        },

        initialize: function() {
            /// <summary>
            /// Initialize the column.
            /// </summary>
            $ADC.GridViewBoundColumn.callBaseMethod(this, 'initialize');
        },

        dispose: function() {
            /// <summary>
            /// Dispose the column.
            /// </summary>
            $ADC.GridViewBoundColumn.callBaseMethod(this, 'dispose');
        },

        renderData: function(dataRow, row, container) {
            /// <summary>
            /// This method is used to render the data cell. You do not have to call this method in your code.
            /// </summary>
            /// <param name="dataRow" type="Object">
            /// The item of the GridView dataSource.
            /// </param>
            /// <param name="row" type="AjaxDataControls.GridViewRow">
            /// The GridViewRow which is passed to render the column data cell.
            /// </param>
            /// <param name="container" domElement="true">
            /// The container cell(td) to render the data of this column.
            /// </param>

            var e = Function._validateParams(arguments, [{ name: 'dataRow', type: Object }, { name: 'row', type: $ADC.GridViewRow }, { name: 'container', type: Object}]);
            if (e) throw e;

            var value = null;
            var dataField = this.get_dataField();
            var dataFormatString = this.get_dataFormatString();

            if (!$ADC.Util.isEmptyString(dataField)) {
                //value = dataRow[dataField];
                /* Begin my edits */
                var dataFieldParts = dataField.split(".");
                if (dataFieldParts.length > 1) {
                    value = dataRow
                    for (var n = 0; n < dataFieldParts.length; n++) {
                        value = value[dataFieldPartsNo];
                    }
                }
                else {
                    value = dataRow[dataField];
                }
                /* End my edits */
            }

            if ((row.get_rowType() == $ADC.GridViewRowType.EditRow) && (this.get_readOnly() == false)) {
                if (this.get_applyFormatInEditMode() == true) {
                    if (!$ADC.Util.isEmptyString(dataFormatString)) {
                        value = value.localeFormat(dataFormatString);
                    }
                }

                if (value == null) {
                    value = '';
                }

                var textbox = document.createElement('input');

                textbox.setAttribute('type', 'text');
                textbox.setAttribute('value', value);

                container.appendChild(textbox);

                if (this.get_controlStyle() != null) {
                    this.get_controlStyle().apply(textbox);
                }
            }
            else {
                if (value == null) {
                    var nullDisplayText = this.get_nullDisplayText();

                    if (!$ADC.Util.isEmptyString(nullDisplayText)) {
                        value = nullDisplayText;
                    }
                }
                else {
                    if (!$ADC.Util.isEmptyString(dataFormatString)) {
                        value = value.localeFormat(dataFormatString);
                    }
                }

                if (value == null) {
                    value = '';
                }

                container.appendChild(document.createTextNode(value));
            }

            if (this.get_itemStyle() != null) {
                this.get_itemStyle().apply(container);
            }
        }
    }

    $ADC.GridViewBoundColumn.registerClass('AjaxDataControls.GridViewBoundColumn', $ADC.GridViewBaseColumn);

    if (typeof(Sys) != 'undefined')
    {
        Sys.Application.notifyScriptLoaded();
    }

     

  • 09-02-2008 10:29 AM In reply to

    • sonu
    • Top 10 Contributor
    • Joined on 05-22-2006
    • Montreal / Canada
    • Slacker
    • Points 9,810
    • MVP

    Re: Support For mapping to Objects

    I haven't worked yet with LINQ, however I would love to see your solution in an example project. Would you mind to send a small project to my email (contact me through the contact form and I will reply with my email)?

    Thanks

    [MVP since 2005] [MCAD]
    Webmaster of DotNetSlackers
    Question or Suggestion?
    Feel free to ask my any .NET question
    Our Posting FAQ
Page 1 of 1 (3 items)