Hi,
Is there a simple way to let new rows be added to the top of an UltraWebGrid rather than the bottom?
Thanks!
Hello pmurdoch,
Please refer to this topic. It shows how to set a UI for adding new rows at the top of the grid (step 5).
Let me know if you have further questions.
Elizabeth AlbertLocalization Engineer
Thanks Elizabeth,
I followed the instructions in that link, but the blank new row still appeared at the bottom. The link was still useful for other things though. I did get the blank row to appear at the top using this:
<addnewrow view="Top" visible="Yes"></addnewrow>
That is a property of the UltraGridBand within the UltraWebGrid.
However, when populate the new row with data and click outside the grid the new row is then moved to the bottom of the grid and a new blank row appears at the top. I would like to keep the newly populated row on top....making it the first row after the new blank row. Any ideas?
Thanks,
Paul
Hello Paul,
I created a sample to try it out, and you're right. The new row is added to the bottom of the grid no matter where the AddNewRow is positioned. I discussed this with a developer, and the short answer is that there is no easy way to do it.
The WebGrid will add the new row to the datasource and then reload the data. Datasources (think of Access for example) will add new rows to the bottom of the data table. When it reloads, it will display the data in the same order as the datasource.
You can try to manually update the datasource and insert the row in the correct index. You can get the row data by handling the AddRow event of the WebGrid (it will be stored in e.Row). After the manual update, cancel the event.
protected void UltraWebGrid1_AddRow(object sender, Infragistics.WebUI.UltraWebGrid.RowEventArgs e) { // Get the row data UltraGridRow newRow = e.Row; // You can also get cell information // String firstCell = newRow.Cells[0].ToString();
// Manually update the data source // with something like a SQL statement // AccessDataSource1.Insert(); // add SQL statement // Cancel the default add row event e.Cancel = true; }
You could also try to use a hidden column with some number value. For example, the existing data would all have a value of 2 and any new rows would have a value of 1. The default view could sort on that column so the newly added rows would be at the top.
If you require further assistance, I can ask Developer Support to create a case for you.
Elizabeth,
I used the sample code you posted. I added a UltraWebGrid1.DataBind(); before the e.Cancel = true; and got the following errors (see below). It runs smooth without the line I added, but the GUI is not updated with the new row of data. Any suggestions?
[NullReferenceException: Object reference not set to an instance of an object.] Infragistics.WebUI.UltraWebGrid.StateChangeProcessor.ProcessAddedRows(StateChange stateChange) +489 Infragistics.WebUI.UltraWebGrid.StateChangeProcessor.ProcessChanges() +5515 Infragistics.WebUI.UltraWebGrid.UltraWebGrid.ProcessChanges(StateChanges stateChanges, Boolean fireEvents) +439 Infragistics.WebUI.UltraWebGrid.UltraWebGrid.RaisePostDataChangedEvent() +161 System.Web.UI.Page.RaiseChangedEvents() +165 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1485
I will forward your post to Developer Support so they can create a case to assist you.