Tuesday, February 20, 2007

ASP.NET 2.0 ObjectDataSource Madness

Ok so after several days and nights of torment, I have learnt quite a lot about GridView controls and binding (or not, as the case may be) to them.


You thought with .NET 2.0 that all your data binding woes had been answered. Oh how very wrong you were, you poor, poor developer (emphasis on poor; these are hard times, what with house prices soaring and whatnot).

It is true to say that you can use an ObjectDataSource in conjunction with a GridView control to present data to the user in a nice tabular format, though you are not likely to achieve this without a) pain b) coffee and c) (in extreme cases) a near-death experience.

Here are some brief and scattered notes on my experiences whilst attempting to use Object Data Sources:

- Update methods can get easily out of synch. There is a hack-around/fix for this - use the ODS 'OnUpdating' method, like so:

//protected void DtypesODS_Updating(object source, ObjectDataSourceMethodEventArgs e)
{
// Modify input parameters because ODS is too dumb to figure it out.
if (e.InputParameters.Contains("DType"))
e.InputParameters.Remove("DType");
}
And obviously add a ref to that in your aspx, or initialise the event by overriding OnInit.

[More to come.]

1 comment:

Katey said...

I found this in your profile

It is the gayest thing I've ever seen

I think I just burst with geeklove <3

Fixes to common .NET problems, as well as information on .NET features and solutions to common problems that are not language-specific.

Fixes to common .NET problems, as well as information on .NET features and solutions to common problems that are not language-specific.

Z