views:

84

answers:

3

hi,

I read somewhere that one of few weaknesses in data binding model is that you never explicitly handle or create the data object that’s bound to the control and as a result you don’t have a chance to add an extra item. But I’m not sure what is meant by that.

What or how exactly would you be able to add an extra item if you were allow to explicitly create a data object? Would you basically be able to bind control to data source and let the runtime automatically fill the control with data source’s data , and additionally that control could also get an extra item from data source by manually creating it?! How would it be able to do that?!

thanx

A: 

What you have read, in my estimation, is pure crap. Up until the point of binding, I can alter the objects in question. One common scenario, for example, is adding a column to rows in a DataTable object (which is actually a collection of rows and columns). I can, in fact, alter by adding a column (let's say sum) to each row.

I can, with some restrictions on classes, do the same with other types of collections and objects.

After I have bound the object, I can still add items to the output by using the databinding method for a row, so I am still not restricted.

In general, I find those that are expounding this garbage are defending using ASP style code in an ASP.NET page.

Gregory A Beamer
A: 

Could you perhaps elaborate on your reply with a bit of code or some additional explanation, since I'm still having problems understanding exactly what is meant by "explicitly creating data objects bound to a control"?

SourceC
A: 

When you use the OnItemDataBound event, you have full access to the underlying datasource object via e.Item.DataItem. You can use this data to populate any controls in the ItemTemplate via e.Item.FindControl("controlname"). You can also use functions inside the <%# %> tags to format text or calculate values.

iZ