Hi, I have a databound UltraWebGrid which updates values to the DB as it should. It does so when the user change a value in the grid and clicks a simple button for postback. However, I like to suggest some values to the user by changing the value by code, but when I do that - the data is not updated on postback.
If the user changes another column on the same row that the code changes, only the user changed-column will be saved to the DB.
foreach (Infragistics.WebUI.UltraWebGrid.UltraGridRow udr in (UltraWebGrid1.Bands[0].Grid.Rows)){udr.Cells.FromKey("categoryid").Value = suggestcategoryid();udr.Cells.FromKey("categoryid").DataChanged = true; // I tried with and without this DataChanged-propertiesudr.DataChanged = Infragistics.WebUI.UltraWebGrid.DataChanged.Modified;//UltraWebGrid1.UpdateDBRow(udr); // this updates the data to the database, but then the user never has the option to cancel}
thanks
WebGrid does not raise any events that you can listen to in response to the program changing data in server-side code; its update-related events (UpdateRow, DeleteRow, AddRow, UpdateCell, and their "batch" equivalents) respond to changes applied on the client. Because of this, if you make a progrmamatic change to WebGrid cells in server-side code, it is up to you to also make the same change in your underlying data source.
Since you're trying to programmatically suggest values, you might consider updating cells on the client instead.
Many thanks!
I thought of going that direction, but it seemed a bit hard, so I hoped I could go "my way" :-).
The cells I am trying to suggest values into are ValueList-cells, and their suggested values depend on a db-query.
The solution I have in mind now is to have one hidden column for each of the cells I am going to handle. And when the user clicks "suggest" the client-side code will copy the value from the hidden column to the visible column.
I am unsure of how to write the client-side code and also - if the hidden column value is accessible from client side.
I found some samples suggesting that I should use display:none; on the hidden column rather than setting hidden=true.
I am still tring to find a way to set the valuelist cell value (valuemember and displaymember differs) by javascript-code.
Found out that the ValueList take's care of Displaymember if I set Value. After a lot of struggling with javascript I came up with this working code:
Reference column is hidden with display:none; Button calls suggestvalues() without postback (return false;).
function suggestvalues(){var grid = igtbl_getGridById("ctl00_SheetContentPlaceHolder_TransactionsGrid1_UltraWebGrid1");var count = grid.Rows.length - 1;var suggestcategoryid="";var row;while(count >=0 ){row = grid.Rows.getRow(count);suggestcategoryid=row.getCell(8).getValue();if (suggestcategoryid!=null){row.getCell(2).setValue(suggestcategoryid);var elem = row.getCell(2).Element;elem.runtimeStyle.backgroundColor = "LightBlue";elem.style.backgroundColor = "LightBlue";}count-=1;}}