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
515
format dates in rowedittemplate textbox with RowEditingClientBinding
posted

I have a WebHierarchicalDataGrid that I dynamically build the boundcolumns and the rowedittemplate. When I add the RowEditingClientBinding, if the date in the bound column is empty the grid shows nothing in the column which is correct, but when the RowEditTemplate opens, in my textbox it displays the word "null". Also if the date is in the bound column is in short date format, when the RowEditTemplate opens, the date is displayed in long format. So how do I not show nulls and long dates in my textbox in the row edit template? I need a server side example only.

 

 

var item = new RowEditingClientBinding

 

 

{

ColumnKey = dataFieldName,

ControlID = clientId,

GetValueJavaScript =

 

 

"$get('" + clientId + "').value"

,

SetValueJavaScript =

 

 

"$get('" + clientId +

"').value={value}"

};

Grid.GridView.Behaviors.EditingCore.Behaviors.RowEditTemplate.ClientBindings.Add(item);

Parents
No Data
Reply
  • 515
    posted

    I figured this out. I created a javascript method to format the date and in the SetValueJavaScript of the RowEditingClientBinding, I wrapped it in the "value":

    var item = new RowEditingClientBinding
                        {
                            ColumnKey = dataFieldName,
                            ControlID = clientId,
                            GetValueJavaScript = "$get('" + clientId + "').value",
                            SetValueJavaScript = "$get('" + clientId + "').value=formatDate(new Date({value}),'MM/dd/yyyy')"

                        };

                        Grid.GridView.Behaviors.EditingCore.Behaviors.RowEditTemplate.ClientBindings.Add(item2);

     //BLOCKED SCRIPT
     function formatDate(vDate, vFormat) {
            var vDay = addZero(vDate.getDate());
            var vMonth = addZero(vDate.getMonth() + 1);
            var vYearLong = addZero(vDate.getFullYear());
            var vYearShort = addZero(vDate.getFullYear().toString().substring(3, 4));
            var vYear = (vFormat.indexOf('yyyy') > -1 ? vYearLong : vYearShort);
            var vDateString = vFormat.replace(/dd/g, vDay).replace(/MM/g, vMonth).replace(/y{1,4}/g, vYear);
            return vDateString;
        }
        function addZero(vNumber) {
            return ((vNumber < 10) ? '0' : '') + vNumber;
        }

Children