This is a migrated thread and some comments may be shown as answers.

[Solved] Remove New record row when rebind (refresh)

5 Answers 164 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Raymond Mui
Top achievements
Rank 1
Raymond Mui asked on 15 May 2008, 09:18 AM
I have a grid, and of course allow user to add new records.  One of the columns consists of a checkbox.  When adding new record row, I assign the checkbox value to True, which working fine. 

However, before the record is saved (by pressing the Save button), if the user click "Refresh" instead, this extra new row causes problem.  The checkbox value becomes "null" and exception raised.

I would like the not-yet-saved new record to be removed from the grid, when the user presses "Refresh".  How can I do this?

Thanks

Raymond

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 15 May 2008, 09:40 AM
Hi Raymond,

Try deleting the newly added row  on clicking the Refresh button in the ItemCommand event(check whether the CommandName="RebindGrid").

CS:
 protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "RebindGrid") 
        { 
            //Check whether the item is Saved 
            //Write the code to delete the newly added row 
             
        } 
    } 


Thanks
Shinu.
0
Raymond Mui
Top achievements
Rank 1
answered on 15 May 2008, 09:47 AM
Thanks Shinu,

I am working on the Rebind command as well.  Actually, I want to know how can I remove the first adding row  from the grid before rebinding.

0
Princy
Top achievements
Rank 2
answered on 15 May 2008, 12:12 PM
Hello Raymond,

In the PreRender event get the  key value for each item in the RadGrid and then find the autoincremented  key value using a Select query from the database. This will return the topmost key value (which will naturally be the last inserted row). Compare these values and Delete the row with the matching ID.

You can refer the following code library as a guideline.
Select Last Inserted Row

Princy.
0
Raymond Mui
Top achievements
Rank 1
answered on 16 May 2008, 06:01 AM
Hi Princy,

The new row is not yet updated to the database, it is only in the Grid. 
0
Raymond Mui
Top achievements
Rank 1
answered on 16 May 2008, 06:18 AM

oh.I found out the solution myself.....the insertion mode can be easily changed as follows:.

If RadGrid1.MasterTableView.IsItemInserted Then
    RadGrid1.MasterTableView.IsItemInserted = False
End If

Tags
Grid
Asked by
Raymond Mui
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Raymond Mui
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or