ASp.Net GridView Updating using a stored procedure - asp.net

I've read tons of sites on this. There are many "Examples" if you call some code with no explanation of how it was generated (design view vs typed) an example or just want to use simple select and update statements.
I have a Gridview. I am populating it using code from a stored proc. Now I want to edit the data. I have nothing set in the properties of the Gridview through design view (datasource, columns, etc.) My question is, how can I set this to allow editing and use a SP to send it back to the database?
Do I have to now manually create columns with code since I chose to not set properties in the design view?
Is it better to set the properties in design view and go that route? I started that way, but had problems when it came to updating with a SP.
I guess the whole do it in the designer vs do it in code thing has me confused.
I started adding RowEdit, RowCommand, etc. to the html and c#, but still don't see the EDIT/CANCEL on the webpage when I run it.

Learn to use the ObjectDataSource. It gives you maximum freedom of what way of storing the data you use - you delegate the select, update and delete to an external class where you just write your code which uses ado, linq, hibernate, a webservice or just anything.
Coding your views directly against fixed database structure would hurt you sooner or later.

Related

Entity framework, custom model, datgrid, paging, sorting not working

I am using vs 2012, .net 4.5, entity framework 5, web forms, vb (but c# help just as good for me)
I am new to using the Entity framework. I have decided to create a new project in .net 4.5 so i can use item Type for strongly typed data controls, in this case gridview.
I need to retrieve data from multiple tables 5+, which by its self is easy enough, but this means i cant use EntityDataSource as theres no option to build a query etc only select a single table. How can i achieve this plesae? I guess in the code behind i can set the gridview datasource but then do i need to implement custom paging and sorting?
I presume in this case i wont be able to use a strongly typed data control but i can live with that, does that mean its only viable for getting data from 1 table. Or do i need to populate my model with all results. The amount of data in the tables is well over 500,000 rows so obviously it has to be paged! And the page has a number of filters / search otpions
I am at a loss here, mainly i obviously am not understanding something.
I have been researching / googling this for a few hours som findings are below, but again they dont really answer or help me.
http://weblogs.asp.net/dwahlin/archive/2013/03/26/asp-net-4-5-web-forms-features-strongly-typed-data-controls.aspx
http://forums.asp.net/t/1677303.aspx/1
One option is creating a view with whatever you want in your database and then regenerating your EDMX to include the view. You will then have a strongly typed object designating the fields in the View.

Developing a short-term web-based data entry UI

Say you had to quickly build a data-entry UI that works in a web browser, which must interface with a business layer, which must interface with a data layer.
You want to connect only to business objects, not directly to the database.
Most of the views of the UI will be simple CRUD operations, with edit/update happening within a grid.
But some of the screens will be more complex, representing many-to-many relationships.
What's the fastest way to achieve this in ASP.NET?
(Note: speed of development is high priority, code quality and re-usability are low priority.)
Entity Framework + ASP.NET Dynamic Data?
If speed of development is the main priority, then go with what you know.
For example, if you know ado.net/enterprise library then go with that. If you know Entity Framework or LINQ, then go that route.
Without a summary of your skills, it's going to be impossible for anyone to tell you the fastest way to get something up and running.
I've written a lot of little business editors like this for my company in the same manner, get it to work quickly, if it's used or needs to be improved, I deal with that later.
Start up a new asp.net project. Add a class library to the solution and reference it from the asp.net application.
Asp.Net Application
Use Master Pages and Themes
Use a repeater for the data lists and command buttons for selecting and deleting.
The repeaters work well for inner lists as well, take note of OnItemDataBound and OnItemCommand.
Use Panels to hold the lists and editors, write some logic to control when to view editors and when to view lists.
If the logic is common, then make some base pages that new editors can use and override.
Class Library
Add your business objects
Add a Linq to Sql class and add database objects as necessary.
To make it simple, you could use the some of the time tested controls and objects:
User Interface Layer: GridView for displaying and providing links for editing and deleting data. Clicking on Edit link may open up a new Asp.net web page that holds FormView for inserting and updating records. Use ObjectDataSource to link methods at the Business Logic Layer to Create/Read/Update/Delete records.
Business Logic Layer: Apart from creating CRUD methods, you might need to use light weight serializable data transfer objects to pass data between different layers and a custom mapper to trnaslate data from and to other layers.
Data Access Layer: Linq to Sql might make the data access and manipulation quick and easy.
It depends on the complexity of the application. I would go with Linq to Sql. But then using Linq to Sql does not necessary provide a good abstraction between the business layer and the data access layer. But I find that using Linq to Sql you can quickly retrieve the data out of the storage and display it on the screen.
Also, if you want fast UI then take a look at dynamic data website. That also uses Linq to Sql or Entity Framework.
One question you must think is that if you need good design or RAD.

asp.net - Possible to have formview edit data across multiple tables?

I am attempting to construct a formview that will edit two related objects at once.
In basic terms, I have a Linq To SQL object of teacher which has exactly one school. The formview has no problem displaying the data, but when in edit mode will only save the changes done to the parent object. Changes to the school data are seemingly ignored
Is there any way to achieve the kind of thing I want here?
Thanks,
This is probably similar to what I'm doing, although I'm not using Linq. I'm using a vanilla ObjectDataSource and displaying data in a drop down list via a different data source. Add a new Event for the FormView that is called during the "ItemUpdating" event. Embed code to directly save your changes in that event. Then as the FormView is saved, everything else is saved.
If you want it to be saved after the FormView, use the ItemUpdated event instead. It's a bit of a manual process, but it does get around the problem.

Suggestions on which ASP.NET control to use?

I've received a project for internal use. My application has to store about 100 rows of meta data of a game and each row has about 15 fields maximum. Fields can be game name, game category, maker, source code path, etc. I will most likely have to join about 5-10 tables for each row of record. Only a few people are using it and will receive very little hits. Speed performance is not a much of an issue. The rows of data I have to present must be sortable and searchable
My current solution is to use ASP.NET's GridView control with ASP.NET's AJAX UpdatePanel to give it that ajax feel. I'm thinking of using LINQ-to-SQL as my data access layer. I'm thinking of building my own custom search engine but if there's an existing control that has this feature already, i would prefer to use that; anyone know of such control exist? Anyways what do you guys think?
Update #1:
I'm looking into creating a DynamicData website. Any have thoughts on that?
Use ext.js!
Look at the Grid Samples, its a very shallow learning curve and provides you with amazing results in little to no time.
http://extjs.com/products/extjs/
Basically, you expose your data via a web service (asmx or WCF, your choice), throw the Ext.Js grid onto your html/aspx page and point it at your webservice. Configure the control for things like sorting/searching/expanding/grouping/paging etc (use the api reference http://extjs.com/deploy/dev/docs/).
ASP.NET Dynamic Data looks really cool, particularly for sites where you've got:
lots of data
not a lot of worries about performance
no / little desire to skin / design the site
no / little desire to extend existing / write new functionality.
So I'd say that's a good match for your project.
Gridview is your best bet. It's so powerful if you know how to use it correctly. It does automatic sorting and if you can code pretty well you can get the data to be filterable(if that's a word). It also makes the Connection to the database for you....so in my opinion, you can't beat the gridview when it comes to reports like that.

Clean way to offer a 'review' stage in an ASP.NET form

I'm currently working on a reasonably complicated data input form, based around ASP.NET Web Forms. After the form has been completed, we'd like to offer a chance for the user to review their input before actually submitting the form (as well as going back to make changes to their data if requried).
Due to the large number of fields, I wanted to use a FormView control due to it's automatic databinding ability, removing a lot of tedious code, however there doesn't seem to be a simple way to offer this functionality.
At the moment, my current approach uses an ObjectDataSource to bind all the form fields. I've created two 'modes' of operation on the data source; one mode temporarily saves the object to the user Session (allowing retrieval again later for read-only/edit modes - this facilitates the review/modification functionality), while the second mode actually does the database insertion.
While this seems reasonably robust at this point, it still feels quite dirty to me. I know I could use a Wizard/Multiview type approach, but then you lose out on the niceties of automatic databinding (I believe?). I'm sure this is a fairly common problem, so how is this typically done in a Web Form environment?
Thanks!
The project I am currently work on uses a custom wizard setup (not the asp.net 2.0 wizards). It comprises of the several steps your wizard may require, and when you go from one step to the next, the code saves the values into a final step (a read-only review). When the user gets to that last step, they can go back to the step that needs to be updated. When happy, the user submits the wizard, and the data is saved to the db. It is basically a series of panels that have their visibility toggled.
You should be able to still use the ObjectDataSource for each of the editable fields, having the panel or mutliview being visible or not shouldn't affect the binding. When you go from one panel to the next, you can update a read-only step (like I said before) while keeping the editable controls bound to the ObjectDataSource. When you go back to any steps that need to be modified, you are still bound, so when you make any changes and click submit or whatever the button is, it should use the ObjectDataSource.
Anyone else have any other ideas?

Resources