I've got a user modification page, that displays a list of reports a user has access to using a GridView object.
What I want to do is, if someone makes a bunch of changes to a users page, but then clicks cancel, all changes that are made will be undone.
My main issue here is the GridView, which has add/delete/modify buttons, tied to a separate table.
So if I open my own page, add a new report to the gridview, then hit cancel, I don't want that report to be saved to my account..
Likewise, if I delete a record, and then hit cancel, the record is not deleted.
What is the best way to do this?
You need to maintain this in the datatable and put this in a Session variable and bind your gridview to your datatable that is in the session. So once you are finished with the changes and want to submit the changes in the DB, you have to play with Datatable Row State, from which you can find which row is added and which one is Deleted or Modified.
Have a look at this article to understand Datatable Row state
system.data.datarow.rowstate
In such case you mustn't bind GridView to the real datasource (Entity framework). If you do it changes will be written to the database and you will have very hard time to roll them back. GridView must work with temporary data stored for example in the session and only after commiting changes (Save button on the page) the data will be written to the database by EF.
Related
I have a table called TableExplorer which contains other table's names and their respective column names.
For example: table Customer may have 5 columns but in TableExplorer I may mention only 2 column names out of 5.
User send me the table name in query string, my job is to find that table name whether it is present or not in TableExplorer which I mentioned initially. If the user mentioned table is present then I should bind that table to a gridview and that gridview should have functionality like edit, delete, update. Finally any operation like edit, delete or update made by user should reflect in the respective table as mentioned by the user.
Database used : SQL Server 2008 R2
Programming language : C#, ASP.NET
Thanks in advance for helping.
Are you using WebForms? I'm far from being a WebForms expert but this is what I'd do:
You create different pages with GridView control, one for each table that you might want to bind, eg. Customer table. You create the CRUD operation for this GridView, Insert, Update, Delete. You create parameters for all the columns that the user might need, some of them could be invisible.
The user goes to his selection page, he choses a table and a list of columns and press Submit his request. Whenever you receive the query string you do 2 things:
Identify what table your user is asking and load the right page, if available. Maybe you can load only the specific GridView control in a specific using Ajax. Or maybe you can simple load another page.
Get the list of columns that the user wants to see in his grid from the querystring. Before showing the grid to him you keep these columns visible and hide/remove from the gridview every other column. You must pass this parameter to your insert/update methods as well.
I think this is a good solution to start, assuming you don't have a list of hundreds of tables, I wouldn't try to create something completely dynamic.
I have list view on first forms if i select a row and click edit button second form open their i do updates in selected row and click ok then database get updated but i don't know how to update list view display on first form according to updated database?
I will bite the bullet and give you an answer... note that this will be all I offer, no long discussion!
Your ListView will be bound to an IEnumerable of data objects. You will be passing the selected data object to the second form, so any operation done on that data object in the second form will instantly show up in the first form - because you passed an object it is by reference, both forms are looking at the same thing.
As for updating after the database save - you can save yourself some trouble and only get a fresh copy of the data object if there was a problem with the save (so what is currently in the database doesn't match the contents of the data object), or if there is more than one concurrent user of the database. If this is the case then you know the identifier of the data, just fetch a new copy then replace the data row in the IEnumerable that the ListView is bound to.
Remember: data binding is your friend. And it is easy to insert and remove from a list.
I am keeping DataTable in session variable.
A GridView having template column checkbox with autopostback set to true.
oncheckchange event of checkbox is tracked to delete or add rows in session DataTable.
Application opens multiple instances of same page and respective GridView on page is source for adding or deleting rows in (one for all) session DataTable.
Now problem is that I cannot click fast on checboxes in a gridview.
Apparently it look like server side process of updating session table is very
slow. Sometimes cached clicks come into action quite slowly. Please guide how to maintain session DataTable efficiently?
Note:
I have checkbox in the header row of every GridView as well, which checks and un-checks every row present in Gridview.
I am trying to debug an issue with a WinForm application.
The application uses a DataGridView bound to a DataSet.
The user can select a row and click "Edit" and an Edit Form appears so the user can edit the row and save his changes.
If the DataGridView is sorted by one or more columns and the user edits a row more than once and changes that rows position in the DataGrid (by changing one of the sorted columns TWICE), the DataGridView gets out of sync and I get Exception errors.
Here is how the code is written:
When the user clicks a row and hits edit (the user may only select one row), that row is passed to the EditFom. The edit Form creates an empty DataSet and loads that Row. When the user is done, the calling form uses DataSet.Merge to merge those changes back into its DataSet.
Here are a couple of scenarios that tell me it is womething to do with the "merge" and sorting:
(Note, I never change the actual "sorting", I am talking about changing the value of one of the sorted by columns in one of the rows.)
If the user edits a row directly in the Grid and changes the value of one of the columns being used to sort, then changes it again, etc. The row moves around the Grid, like it should and when the user clicks save, everything saves fine.
If the user edits a row (directly in the Grid OR via the "template") and doesnt change any of the "sort" columns, just makes an edit (therby setting the "State" of the row to Modified, right...), THEN the user edits the row using the Template (which goes through the seperate DataSet and merges the data back when done), and changes one of the columns being sorted (when done, the grid should resort and the row should "move"), the row doesn't get REPAINTED, it stays in the same position in the grid that it was in before the template edit. (Although, the data saves fine and you can refresh the grid and it sorts properly.) Evidently, the DataGrid isn't being notified that the RowChanged in this scenario (or it is, but it isn't doing anything about it).
If the user edits a row directly in the Grid, change a sort column (the row moves), then edits the row using the template and changes that column again, we get the same results as 2, above. The data saves fine, but when the user leaves the edit template, the grid doesn't resort.
(This is the one that causes the Exception error.)
If the user edits a row using the template and changes a sort column and leaves the template, the datagrid resorts and the row moves properly. Then, if the user edits the SAME row using the Template Edit and changes the sort column AGAIN. When the user leaves the edit template, the datagrid doesn't resort and when the user saves the data and the grid refreshes, we get an error:
System.InvalidOperationException: DataTable internal index is corrupted: '5'.
And sometimes, we get an error complaining the primary key is missing.
Any advice on how to "debug" this? I feel like it has something to do with the "internediate" dataset the edit template uses and the "Merge". It is like the DataGrid datasource is getting out of sync with the DataGrid Rows.
I should have done some Google'ing before posting this. It seems to be a common error and I found a HUGE post about this on the MS site. Unfortunately, I haev tried most of their suggestions, but most likely I will find my answer there. I just wanted to make a note of this, in case anyone is interested:
http://social.msdn.microsoft.com/Forums/en/adodotnetdataproviders/thread/18544cd3-1083-45fe-b9e7-bb34482b68dd
Not sure if I have the correct subject line. Here is my issue. I have a form with 2 GridView. One GridView has a list of all zipCodes. The users is to select a location from a dropdown list, then select the zipcodes he/she wants to be assigned to that location and then click the "Add" button. The zipcodes then appear in the second GridView. When the user clicks the "Save" button, the data is sent to the database. The is also a "Remove" to remove zipcode(s) in the second GridView.
How do I track changes only in the second GridView. There could be 1000's of zipcode in the second GridView. Do I just remove and re-insert the list for that location evertime the user click save? I was thinking of using a DataSet, add DataRows and then update, however I am not using a DataAdapter to load my dataset, so there is no way for me to use DataAdapter.Update(ds). I am using the SQLHelper.ExecuteDataset(parms)
Any ideas?
Anyone?
Forget Dataset. Dataset is a nightmare. Instead use a BindingList.