Dear Infragistcs Support,
I have an unbound UltraWebGrid on an .aspx content page which utilises a Master Page. The grid has two columns of information and one column with the button data type which I intend to use as a delete button. The grid is populated by using a DataReader and manually adding the cells and rows.I want to delete rows from this table, but the UltraWebGrid does not respond in ways that I would expect.
The UltraWebGrid is within an AsyncRefreshPanel and when I click the buttons the ClickCellButton event fires on the server exactly as I would expect.
For removing a row the documentation suggests that enter the following:
e.Cell.Row.Delete
This has the effect of removing the row. However, I'm unable to read the data from the row first in order to make a SQL DELETE query to remove the row.
I have tried:
e.Cell.Row.Cells(1).Value (returns empty)
e.Cell.Row.Delete (and trying to capture the .DeleteRow event, which never fires).
However if I explicitly state: UltraWebGrid1.Rows(1).Cells(1).Value I can read the value. However e.Cell.Row.Cells(1).Value (replace the integers at will) never returns anything.
Also if I throw up a messagebox (to ask the user "Are you sure?") the grid values all simply dissapear. Is this a new bug or perhaps related? Is the server not somehow persisting the information from the client?
Please help! I just want to click a button and query the grid on the server and then repopulate the grid.
Many thanks for your time,
Mike
edit: I'm using .NETAdvantage 2008.2 in Visual Studio 2008 with a .NET 3.5 solution.
make sure that the rows that are being added has view state enabled
Ok, to set the row viewstate preservation on postback a boolean property value needs to be set (true) in the constructor of the UltraGridRow object.
Retesting now.
Hi Duc,
Thanks for your reply, although I'm really confused now.
The e.Cell.Row.DataKey field for all my rows is empty/nothing.They should be blank though since I'm not providing it when I add the new rows, I'm not sure where the DataKey should come from.
The unbound grid example code that I've found doesn't talk about the Row.DataKey either.
I'm not rebinding the grid, since it was never bound to begin with. I can't see any property for adding view stateon a row by row basis or for the whole grid. Do you know where I might find this property setting?
Many thanks,
It looks like the click cell button event should be adequate to persist the deleted row. I've tested this with a WebGrid inside the WARP, the event sends you everything you need; most importantly, the e.Cell.Row.DataKey field. This will allow you to obtain the row from your data base and delete the record.
Remember to have the DataKeyField property set on WebGrid in order for the row to have a DataKey. Since you are deleting the row on the server, you do not need to use the DeleteRow event. If you are in doubt of using this property, check the link I've posted to see how to use it. The key allows you to find the row in the data base.
As for your data disappearing, check that you are not rebinding the grid. You state that you are adding rows and your grid is unbound, make sure that the rows that are being added has view state enabled and that your grid as a whole has viewstate as well. Without it, you will lose all your rows on postback.