Options besides FormView for data binding web forms - asp.net

I don't much care for the template rigmarole of the ASP.NET FormView web forms control. It seems the only way to access template defined controls is to 'capture' module level references to the wanted controls in the ItemCreated data binding event, for use in other tasks and event handlers.
Ideally I would just like to be able to call set this.DataSource and call this.DataBind on a page, but only the latter is possible through inheritence, and doesn't achieve any of my normal data binding needs.
What else is there besides the hairy, scary FormView control?

There is the DetailsView control which renders a 2 column table to setup a form. Very uniform control though, so there is limited flexibility if you need that.
Are you looking for all .NET framework or also any OSS or third party?
HTH.

Related

ASP.NET Gridview Updating Capabilities

The Gridview control in ASP.NET provides updating capabilities when assigning a SqlDataSource control to the Gridview's DataSourceID, however when programmatically assigning a code level SqlDataSource to DataSource, the built-in updating capabilities go away and you are forced to roll your own. Why? What is the difference here, since all we're doing is referring to the SqlDataSource directly, instead of by ID? Why can the GridView still not take advantage of the SqlDataSource UpdateCommand?
Well, the first case, it has 2 native controls. Web and Data. You can perform RAD via VS.NET via their visual and configuration tools. MS ensure that the framework can allow such visual controls to data controls coupling in the aspect of CRUD automatically.
Second case, when you have your own SqlDataSource which is not one of the data controls, you are on your own. That's how it is. I hope someone can tell us a solution for it too.
my 2 cents.
I've discovered that it's possible to programmatically create a SqlDataSource, give it an ID, and assign the properties as follows to allow the built in editing to be mapped properly:
gvData.DataSourceID = dataSource.ID

Asp.net User Control with underlying control editor functionality

ASP.Net 3.5
I want to create a user control that contains the ListView and DataPager controls along with some custom code in the ItemDataBound that is generic and deals with UI styling.
Ideally, when the developer uses this control, I would like to retain editor support so they can select a datasource, add/remove columns, etc...
Is this easy? If so, any references on how to do this?
If it is not possible, what alternatives are there?
The reason I am trying to create the user control is to make it easier on the developers to retain the ui look and feel and to encapsulate common UI styling code.
You'll need to use the Facade pattern to delegate the exposed designer properties to the composed inner controls.
In my opinion it's honestly not worth the effort it would take to wire up nicely.

Data binding on a simple detail form

I created a simple detail edit form earlier, and decided to data bind some controls on it. Of course, I was told they needed to be on a data bound container. My immediate, rather uninformed choice was a FormView. Is this appropriate? What containers could I use here?
Wrapping my controls in the ItemTemplate of the FormView of course made them inaccessible to my code, forcing me into many FindControls and casts, which is just untidy. I know I can write helpers and extension methods that make this much neater, but I just wanted a quick demo. Am I missing something regarding dealing with templated, and this 'nested' controls in this situation?
Your choices are the FormView or DetailsView controls. The primary difference between them is that DetailsView does all the work for you whereas FormView requires you to create your own templates, thus allowing greater control. As you've discovered, FormView requires using FindControl to access the controls, but the intent with data binding is that you shouldn't need to frequently access the controls directly.

Having different asp.net controls tied to each other by having the same datasource

In Winforms you can have two controls tied to the same datasource in a way that when you select a record in one of them, the same record is selected in the other control.
Something that has always bugged me is being unable to non programatically reproduce this behavior in web development. Is there any way to do this, framework, control toolkit, anything?
You will be able to in ASP.NET 4.0 with Sys.Observer.makeObservable.
The short answer is no.
In order to achieve this result in Windows Forms, the data presenter control (a DataGrid for instance) needs to trigger an event handled by the Datasource that, in turn, (as it keeps a list of all data presenter controls bound to it) order them to rebind.
Although this effect can be reproduced in a web scenario, it's definetly not simple because of a simple fact: It's not single layered. The Datasource is on server.
The framework or control toolkit that would expose this feature would need to create a client representation of the Datasource that would reproduce the process I described in Javascript or other technology.
I personally know Telerik, DevExpress and some other widely used frameworks and I ensure you. " non programatically" you won't be able to do this.

ASP.NET WebForms Data Binding Solutions

I am looking for some easy to use data binding to forms controls. Something that will handle formatting, validation and error handling, something that will handle filling controls from business object/DTOs and vice versa with minimal code. I did use google and have found these two links:
Implementing two-way Data Binding for ASP.NET
Using Reflection to Bind Business Objects to ASP.NET Form Controls
I am curios if there is something newer and more complete.
Are you using FormView or manualy fill controls and variables or something else?
I have always used the standard asp.net DetailsView/FormsView controls along with either SqlDataSource or ObjectDataSource controls to accomplish what you are trying to do. This will allow you to do two-way data binding and with a small amount of coding with template fields you can add validation and formatting.
Take a look at http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/formview.aspx for more information.

Resources