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 =
,
SetValueJavaScript =
"').value={value}"
};
Grid.GridView.Behaviors.EditingCore.Behaviors.RowEditTemplate.ClientBindings.Add(item);
Now I'm adding logic to my grids for columns short date and time "MM/dd/yyyy hh:mm tt". I have my bound column formatted with the short date time and my roweditemplate textbox is formatted this way as well. But when my roweditingClientBindings.GetValueJavaScript fires, it does not set the date and time in the cell I was editing and completely clears it. So how do I set the cell value in the grid to the "MM/dd/yyyy hh:mm tt" format? Note if I do not set the time it works. I'd rather use my textbox (with is using a custom jquery datetimepicker control) then your DateTimeEditor controls. And if I need to reformat the date again in a javascript method that is fine, I just need to know what format the date needs to be in.
//Bound column formating:boundColumn.DataFormatString = "{0:MM/dd/yyyy hh:mm tt}";
//In my Edit Templatevar item = new RowEditingClientBinding { ColumnKey = dataFieldName, ControlID = clientId, //reformat is my js method GetValueJavaScript = "reformatDate($get('" + clientId + "').value)", SetValueJavaScript = "$get('" + clientId + "').value=formatDate(new Date({value}))"
//BLOCKED SCRIPT function reformatDate(vDate) { //So how do I reformat the date here? return vDate; }
Hi ratkinson,
I'm glad you figured this out. Another option would be to use one our our DateTimeEditor objects. This should accept null and display blank. You would just need to change the get and set bindings to use $find and then the client methods of the editor.
regards, David Young
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; }