User Profile & Activity

Glenn Layaar Support
Page
of 99

Based on my analysis on the provided user code snippet, the MoveRow function only select the cell. If you would like to enter edit mode automatically, you will need to modify the MoveRow function. Here is the snippet, this snippet is already using the new WebGrid API introduced in version 5

function MoveRow(destRow, destCell)
{
var grid = ISGetObject("wgTest");

grid.GetRowByElement(destRow).Select();
grid.GetCellByElement(destCell).ActivateEdit();
}


According to our developer, the earliest server side event will be control load server side event. For example in ASP TextBox it will be during OnLoad server side event handler.

Posted: April 8, 2010 12:48 AM

I did not found any attachment in your post. However based on my test on your scenario, you could use the GetRowByKeyValue client side function to determine if the row your are going to add has already exist. The function will return null if the row does not exist.

Here is a snippet:

grid.RootTable.GetRowByKeyValue(KeyValue);



WebGrid will rewrite the style and class name after updating a row. If you wish to preserve the style you set during ExitEditMode client side event you will need to buffer the modified style during BeforeUpdate client side event handler and re-apply the style during AfterUpdate client side event handler. Here is the snippet, I am using class name to modify the edited cell:

var EditedCell = "";
var KeyValue = "";

function wgTest_OnExitEditMode(controlId, tblName, editObject)
{
var wgTest = ISGetObject(controlId);

editObject.cellElement.className += " Edited-Cell";

return true;
}

function wgTest_OnBeforeUpdate(controlId, tblName, rowObject)
{
var wgTest = ISGetObject(controlId);

var rowStruct = ["ID", "Name", "Author", "Category"];
for (var i = 0; i < rowStruct.length; i++)
{
var className = rowObject.GetCell(rowStruct[i]).CellElement.className;
if (className.indexOf("Edited-Cell") > 0)
{
EditedCell += rowStruct[i] + ";";
}
}

KeyValue = rowObject.KeyValue;
EditedCell = EditedCell.length > 0 ? EditedCell.substr(0, EditedCell.length - 1) : EditedCell;

return true;
}

function wgTest_OnAfterUpdate(controlId, tblName, rowObject, xmlResponseObject)
{
var wgTest = ISGetObject(controlId);

setTimeout(function()
{
var rowEditObj = wgTest.RootTable.GetRowByKeyValue(KeyValue);
var rowStruct = EditedCell.split(";");
for (var i = 0; i < rowStruct.length; i++)
{
rowEditObj.GetCell(rowStruct[i]).CellElement.className += " Edited-Cell";
}
EditedCell = "";
KeyValue = "";
}, 10);

return true;
}


You could try setting a new css class in the cell element of the disabled row and mark the style with !important so it will not be overridden by the selected row style.

Here is an example of such workaround. Assign the new style to the disabled row for example, the row with key value 3 and WebGrid column ID, Name, Author, Category during the WebGrid AfterInitialize client side event.

function wgTest_OnAfterInitialize(controlId)
{
var wgTest = ISGetObject(controlId);

var rowStruct = ["ID", "Name", "Author", "Category"];
var rowObj = wgTest.RootTable.GetRowByKeyValue("3");
for (var i = 0; i < rowStruct.length; i++)
{
rowObj.GetCell(rowStruct[i]).CellElement.className += " Disabled-Row";
}

return true;
}

Mark the css property as important so it will not be overridden by the selected row style:

<style type="text/css">
.Disabled-Row
{
background-color: Red !important;
font-style: italic;
}
</style>


Could you elaborate on the scenario you are trying to achieve? As far as I understand, the textbox value will be ready after invoking the RenderControl function.

I have prepared a simple sample in which the textbox value will be inserted with the newly added row and retrieve during a button click using flypostback.

Posted: April 7, 2010 12:10 AM

In the provided sample BatchUpdate_Enterprise.aspx, I have tried the scenario you described, adding multiple row with duplicate KeyValue. However, internal WebGrid validation on every pending changes will already disallow such operation.

In your scenario, which event handler are you using in an attempt to cancel the row addition? In your scenario, does the message occur after each pending changes or after accept all changes occurs?

Posted: April 6, 2010 10:58 PM

Attached is a simple sample that demonstrate the datasource is cached and show the rows count of the data source.

You will also need to have the global.asax file in your project in order to ensure caching works. 

Posted: April 6, 2010 10:05 PM

Unfortunately the SetCurrentPageIndex function is only available in WebGrid 7.

In WebGrid 6, the available function is the GoToPage which is a javascript function that you have already mentioned in your first post.

Currently I do not have any workaround to set the current page index in the server side for WebGrid 6.

Posted: April 6, 2010 12:33 AM

My test show in order to enable data caching in the WebGrid you will need to set the AllowAutoDataCaching to true. You will not need to use the AddDataSourceToCache function.

In order to retrieve the cached data please use GetCachedDataSource function.

All times are GMT -5. The time now is 4:50 PM.
Previous Next