I recently began working on a project which has many gridviews on a single page. During creation of a new record, the user needs to be able to add/remove/edit these gridviews and then save to the database at the end. The problem with this obviously is that there is no datasource to bind the data too until after its written to the database.
This data represents a 1..* relationship, which is why the gridview data cannot be written to the database until the parent record has been created first.
The best way I have found so far to solve this is to use viewstate. This solution however does not seem ideal to me. I am also forced to manually create the gridview functionality with OnDeleting, OnUpdating, etc so that I can manage the binding of the viewstate with the gridview.
Does anyone have any suggestions on a better way to manage this situation, it seems like it would be a common thing?
UPDATE:
Keep in mind this data needs to be around throughout postbacks.
Use a DataSet as an intermediate connection to your data source. Fill the DataSet with your data and then bind your GridView to the DataSet setting the GridView DataMember to the name of the table it is supposed to bind to.
As the user updates tables it will add/modify records in the DataTables in the DataSet. When the user is done editing and clicks "Save" your code can then update the database from the datasets, either automatically using a DataAdapter, or manually looking at the RowState of the rows in the DataTables.
Use a DataAdapter and a Dataset. Invoke the fillschema method in the adapter to create de metadata (cols, constraints, relations, etc) in the dataset. bind the data tables created to the different grid views. update manually cheking each row rowstate on each table or call the adapter's update method to do it automatically. If you do it automatically you need to define commands for insert, delete, and update in the adapter.
Related
I have a SAP UI5 V2 odata model with a two way binding to a table and to a form.
The table is displaying all records, and when clicking on a record, I am using setBindingContext to bind the selected table record to the form for editing. When typing in the form, the values dynamically update in the table (because of the two way binding). model.submitChanges() writes the change back to the server.
So displaying the list, and editing records in the list are working just fine.
Now for the problem How to create records with the same form?
I also want to use the same form for adding new records, but I cannot figure out how to unbind the form from a previously selected record, or otherwise create a new blank entry in the data model to be sent to the server.
All of the tutorials I have been able to find on doing UI5 Odata CRUD operations don't really address this problem.
I discovered this example in the documentation which pointed me in the correct direction.
In summary, you use the oModel.createEntry method to create a new entry in the oData Model. You then have to bind this new entry to your form with setBindingContext - this is the part I was missing.
I need help choosing between Telerik RadGrid and DevExpress ASPxGridView for Asp.Net based on unique filtering requirements. The data lives in denormalized Vax files. All data access is via Sql Server stored procedures calling ODBC Connx queries to the flat files. Stored procedure parameters are used to filter the data. Without any filter thousand of records are returned.
I've successfully displayed all records on two test ASP.net pages, one with DevExpress ASPxGridVIew and the other with Telerik's RadGrid. In code I databind each grid to the stored procedure that returns over 26,000 rows. The sproc is called via an Entity Framework function import that fills an IEnumerable<Customer> which becomes the datasource of each respective grid. I'm able to use the filter features of both grids and they seem to work nicely.
My problem is that before the grid filter is applied all of the thousands of rows are returned from the stored procedure. I'd like to intercept the grid's filter parameters and apply them to my stored procedure parameters. That way far fewer records will be accessed.
Can this be done with either 3rd party grid and if so how?
Thanks in advance.
It seems it can be achieved using a RadFilter to the RadGrid. One example here.
But in general, looks like you'd need to add a handler to ItemCommand, and perform the appropriate filter based on the CommandName, for example. You could then just rebind the data.
The Rad Filter will also allow you to use it without being directly tied to another control or datasource. The filter has an option to extract a filter expression in many different forms (linq provider is one of them). You can then apply that expression to your datasource. We are doing something similar. We have a page where we dynamically create the rad filter with the types of fields and filter options. The user then uses the rad filter UI to create the filter based on the desired fields, then we extract a filter expression we can apply to a datatable that is created on the page that shows the data.
Here is the code for extracting the filter expression from the filter:
var provider = new RadFilterSqlQueryProvider();
provider.ProcessGroup(myRadFilter.RootGroup);
var sqlFilterExpression = provider.Result;
I implemented paging for one of my GridViews. Now I want that all checked boxes(which are kept in first column of GridView) to be inserted to Database. How can I achieve this? Please let me know.
I want to know how can I save the checked rows to the data table, and then re-bind to this temporary data table to grid view
If some body navigate back and uncheck check box for the row then how can i remove it again from the temporary datatable
Using a gridview and DataAdapters you can achieve this. Read more about updating data with DataAdapters here. To quote Microsoft on the use of DataAdapters:
You can use a data adapter to perform
the following operations:
Retrieve rows from a data store into
corresponding data tables within the
dataset.
To retrieve rows into a dataset, use
the Fill method on a data adapter
object (SqlDataAdapter,
OleDbDataAdapter, OdbcDataAdapter, or
OracleDataAdapter). When you invoke
the Fill method, it transmits an SQL
SELECT statement to the data store.
Transmit changes made to a dataset
table to the corresponding data store.
To transmit a dataset table of the
dataset to the data store, use the
adapter's Update method. When you
invoke the method, it executes
whatever SQL INSERT, UPDATE or DELETE
statements are needed, depending on
whether the affected record is new,
changed, or deleted.
I am using GridView in asp .net and editing data with edit command field property (as we know after updating the edited row, we automatically update the database), and I want to use transactions (with begin to commit statement - including rollback) to commit this update query in database, after clicking in some button (after some events for example), not automatically to insert or update the edited data from grid directly to the DB...so I want to save them somewhere temporary (even many edited rows - not just one row) and then to confirm the transaction - to update the real tables in database...
Any suggestions are welcomed...
I've used some good links, but very helpful, like:
http://www.asp.net/learn/data-access/tutorial-63-cs.aspx
http://www.asp.net/learn/data-access/tutorial-66-cs.aspx
etc...
Well,
you can store your edited data in a DataTable in session. and then pass this data table as a bulk insert in to the database. 2 options are available for this
if you are using SQL Server 2005 you can use OpenXML to achieve this, as i have stated here
if you are using SQL Server 2008 youc an use Table Variables like i did here.
i hope it helps
First way:
Create session variable that will contain your DB object (DataTable or mapped objects).
The GridView should work with this instance instead of sending the data to the database.
Once editing is finished you may take the object from the session and save it in the way you normally do.
Second way:
I would use javascript to collect all changes on the client side while he is editing as a array of objects (each object is separate row).
Once the editing done, you can create json string from the collection and pass it to the server.
If your json object configuration is same as server class then you can use JavaScriptSerializer to deserialize your string into collection of object.
After that, you can save your objects in the way you normally do.
I'm making an ASP.NET Web Forms application. I would like to get a DataSource which takes its data from a DataTable, and this table is persisted among requests (preferably in session, not ViewState).
The idea is that there is a need for some fairly complex forms where there are several gridviews in each of them. All the gridviews have to have edit functionality (we're using DevExpress), but there has to be one giant "SAVE" button on the form, which saves everything.
So it would be nice if I could get some kind of a DataSource that I could bind these GridViews against and which would only store the data in memory. When the user clicks the Save button I would then manually query these DataSources and extract the changed data from them.
Is there something existing for this, or must I write my own (seems to be a pretty large task)?
The scenario you have described;
Retrieve data from datasource and
store in datatable
Store datatable
in session-state.
Modify datatable
from different grids
Sounds like it will work, issues that i can see you having is that you'll have to reload the data between grids when the data changes. You'll have to write a class that'll raise events when changes are made to the datatable (which you'll probably also want to include in the class, and just store the class object in session state).
I hope the datatable isn't too too big... as this isn't the sort of approach i'd take for a web app.