Are DetailsView /FormView enough rich for Edit and Insert? - asp.net

I'm wondering are DetailsView/FormView and ObjectDataSource have enough capability for Inserting/Editing your records or not ?
Or better ask you Do you prefer use them or make your form by your own ?
Because some times it's not easy to use them for complicated task , On the other hand when you have a lot of fields , that's over killing make your form by your own.

No doubt you can use asp.net detailsview and formsview to edit, insert, display data. This makes it easier and faster to play around your data, if you are handy with it. Otherwise you may stumble with some typical odds, of which almost all are answered and you can find them over Internet. Conclusion: Once you get with formsview, detailsview they will be your favourite tools! That is what Microsoft wants of developers.
Still there are some points to remember: if you have forms with lots of controls and you need them interact with each other, you need to consider playing around the straight ways of formview, detailsview. In such case, you would feel very easy if you had created your own UI with necessary controls.

Yes, they do. Each of these has an insert/edit template. You can make them work, and they work fine. Have used them in my own applications. Complicated tasks, formview should be able to handle because you have full control over the UI and layout.
If you have a large form, detailsview allows you to specify fields and allows the control to do the work (you simply specify the data and detailsview handles the form), but of course with a custom UI the formview is the way to go, and yes it can be tedious to have to create large forms... but it's something we developers must do, either find or create a form builder control or create the UI markup ourselves.

Related

asp.net Pattern for handling View/Edit/Insert situations

I am an asp.net beginner and thinking about designing a website with a typically Master-Detail view. There is a GridView-Control which is displaying all Records and Detail view below to edit existing records, add new ones and display one in detail.
There are several controls in asp.net which can handle such situations: GridView in combination with DetailsView or FormView. But all these approaches do have in common that they seems to be designed for Rapid application development. I want to use my own DAL and so on, so I need to have full control over Insert/Update statements for example.
Whats the typical asp.net approach for dealing with this?
Should I create a UserControl for the Detail view which saves its state (View/Edit/... mode) on its own? Furthermore the view differs only slightly with its state (for example the Insert view does have one more Input-control than the edit view). It seems that the mentioned DetailsView and FormView cannot handle this either and so I have a lot of copy&paste like code.
I think thats all a pretty common situation. What do you prefer in those situations?
You can bind manually data from your custom DAL to the DetailsView or FormView directly like so:
this.dvw.DataSource = new[] { DAL.GetObject(1) };
this.dvw.DataBind();
Or you can also use the ObjectDataSource, which wires up to your DAL object and invokes the method when it needs it.
You can also use a custom user control and load the data manually, which is an approach I have taken in my applications too.
It really depends on your architecture, what you want to achieve, how complex your object model is, and a variety of other factors.
For the Master part, I build the interface by hand, I mean, creating textboxes, labels, etc.
For the Details part, I use a editable GridView. This a tedious task.
Of course, you can use some scaffolding to generate ASP.Net code for your UI from the database model.
You can check this: http://codepaste.net/b1geac

What's the official Microsoft way to track counts of dynamic controls to be reconstructed upon Postback?

When creating dynamic controls based on a data source of arbitrary and changing size, what is the official way to track exactly how many controls need to be rebuilt into the page's control collection after a Postback operation (i.e. on the server side during the ASP.NET page event lifecycle) specifically the point at which dynamic controls are supposed to be rebuilt? Where is the arity stored for retrieval and reconstruction usage?
By "official" I mean the Microsoft way of doing it. There exist hacks like Session storage, etc but I want to know the bonafide or at least Microsoft-recommended way. I've been unable to find a documentation page stating this information. Usually code samples work with a set of dynamic controls of known numbers. It's as if doing otherwise would be tougher.
Update: I'm not inquiring about user controls or static expression of declarative controls, but instead about dynamically injecting controls completely from code-behind, whether they be mine, 3rd-party or built-in ASP.NET controls.
This greatly depends on the problem at hand, and the type of controls you're recreating. Are they all simple text boxes or various different complex custom user controls. the main thing here is: if you want your dynamic control to regain state after a post-back, you have to re-create it in the Init phase of a page life-cycle.
Anyway. There's nothing like a Microsoft way or Microsoft recommended way basically. When you're dynamically adding several simple controls of the same type a hidden field with a count would do the trick, but when you have several complex controls other ways would have to be used. You could still hidden fields and save control's full type strings in them (ie. System.Web.UI.WebControls.TextBox) and re-instantiate them. But think of an even more complex example of putting various controls on different parts in the page... And initializing them to a specific state. That would be a bit more challenging. Hence no Microsoft way... The recommended way is to recreate in Init phase. And that's it.
Everything can be solved, but sometimes one took a wrong direction in the UI and things could be done easier using a different approach.
Additional explanation
This state-full technique of ViewState that Asp.net uses is considered the worse culprit with web developers in general. That's why Asp.net MVC developers think the new framework is bliss since its much more suited to the state-less HTTP protocol. Me being one of them. :D

To build, or not to build a kind of Gridview control from scrach?

I want to show some results in a GridView kind of way.
But for each page I want to show 3 "inner Repeaters" showing data from 1-10,11 20 and 21-30 respectively. You can see this in the folowing image.
alt text http://img196.imageshack.us/img196/1285/examplesv.jpg
My question is, is this easier to buid with only one gridView, and several Item Templates,
OR should I buid a new user control from strach?
I'd recommend building your own user control from scratch for this. Even when used for its intended purpose (displaying table-based data), working with the GridView is like having a root canal.
In general, when it comes to non-standard UI elements (like what you're doing), you will probably end up spending much more time trying to hammer an existing control into the shape you need than you would just writing your own from the ground up.
Do you need all the functionality of a gridview, or are you just rendering and paging data? If not, then perhaps the Gridview is not the appropriate control to build from.
Also, be sure to look into the new ListView and datapager controls.
http://www.west-wind.com/WebLog/posts/127340.aspx
I'd have a close look at ExtJS's Grid. It's impressive looking and has a lot of features you need. The JS file generated may be a bit large though so maybe build your own if you're putting this on the internets.

ASP.NET Repeater Paging/Sorting

So what's the real story on how to do this. All of the examples I find use Default Paging (HOW does anybody find that acceptable???) but I want to use custom paging. I can't use a GridView because I need more flexibility. The examples I see all use the PagedDataSource class but I can't find one that uses Custom Paging. Am I doomed to have to roll my own paging/sorting solution to avoid the bloatware of the other build-in methods?
A simple repeater used for paging where a few page numbers are rendered horizontally is pretty easy to code up and re-use.
I think most people who need this much custom work will reach for a third-party control toolkit, like Telerik, DevExpress, Infragistics, or ComponentOne.
If you want to do it once you'll probably want to do it again, and therefore it's worthwhile to have a quality, re-usable, generic, tested solution available.

Is the ASP.net GridView control a clever design?

I have been using gridview since a long time. I have a "cant live with you and cant live without you" relationship with it.
The idea of Edits, inserts and deletes from within the grid is great but having to do something like
var sometext = ((TextBox)editRow.FindControl("tbSomeText")).Text;
just seems very un-clever to me. Has anyone comeup with a solution or knows (resource) where you perform CRUD operations + paging and sorting from within the grid and dont have to write ugly code (like above). I am not looking for solutions using DataSource objects since I am not its biggest fan. I will be happy if someone can tell me how to live without GridView in asp.net.
I understand there are AJAX implementations but I am looking for something completely serverside.
I always use repeater control instead of others. Because i feel free with it. I build up the html by myself and can do a lot of thing like paging sorting. But of course you need more effort for the repeater for these kind of functionality.
For CRUD operations, i use jQuery thickbox (modal pop up and iframe).
My choice is Repeater
If you are trying to make a basic CRUD website, have a look at ASP.NET 3.5 Dynamic Data which is a great website to add as a pure data access website with CRUD ability. However, its extremely customizable.
Gridview has its advantages and I used to love it in the .Net 2.0 times about two/three years ago. However, since then there are much better .Net 3.5 controls (like ListView) that give you a better ability to customize content. I'd also have a look at many third party grid tools from (Telerik, Infragistics, ComponentArt, ComponentOne, DevExpress) that have a lot more capability than the inbuilt gridview control.
I despise it, every time I've used it or seen another developer use it, they almost always end up going with something else. I've never once heard any developer I've worked with say "I love GridView".
You can hook up the GridView and DetailsView and use basic SQL scripting or complex business objects along with DetailsView.
I have found DetailsView to be very useful.

Resources