Add new row to the top of an UltraWebGrid

Answered (Verified) This post has 1 verified answer | 6 Replies | 2 Followers Thread's RSS feed.

pmurdoch
Points 155
Replied On: Wed, Mar 9 2011 11:28 AM Reply

Hi,

Is there a simple way to let new rows be added to the top of an UltraWebGrid rather than the bottom?

Thanks!

  • Post Points: 20

Verified Answer

pmurdoch
Points 155
Answered (Verified) Replied On: Fri, Mar 18 2011 3:57 PM Reply
Verified by pmurdoch

Hi Elizebeth,

I solved my issue by calling the data source Select().  I inserted the two lines into the code from your last post.  See below.

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

        DataSourceSelectArguments dsa = new DataSourceSelectArguments();
        UltraWebGrid1.DataSource = datasource1.Select(dsa);      

 
        // Cancel the default add row event
        e.Cancel = true;
    }

Thanks for everything,

Paul

  • Post Points: 25

All Replies

Replied On: Wed, Mar 9 2011 2:18 PM Reply

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 Albert
Localization Engineer

 

  • Post Points: 20
pmurdoch
Points 155
Replied On: Wed, Mar 9 2011 3:39 PM Reply

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

  • Post Points: 20
Replied On: Wed, Mar 9 2011 5:19 PM Reply

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 Albert
Localization Engineer

  • Post Points: 20
pmurdoch
Points 155
Replied On: Thu, Mar 17 2011 5:59 PM Reply

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

Thanks,

Paul

  • Post Points: 20
Replied On: Fri, Mar 18 2011 3:33 PM Reply

Hello Paul,

I will forward your post to Developer Support so they can create a case to assist you.


Elizabeth Albert
Localization Engineer

  • Post Points: 20
pmurdoch
Points 155
Answered (Verified) Replied On: Fri, Mar 18 2011 3:57 PM Reply
Verified by pmurdoch

Hi Elizebeth,

I solved my issue by calling the data source Select().  I inserted the two lines into the code from your last post.  See below.

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

        DataSourceSelectArguments dsa = new DataSourceSelectArguments();
        UltraWebGrid1.DataSource = datasource1.Select(dsa);      

 
        // Cancel the default add row event
        e.Cancel = true;
    }

Thanks for everything,

Paul

  • Post Points: 25
Page 1 of 1 (7 items) | RSS