Question

Does the DataList Control in ASp.net 4.5 support Strongly typed Model Binding? I think of the DataList control as a 'Data Control' and in asp.net 4.5 the data controls support the ItemType attribute and the SelectMethod attribute in order to allow strong typing. But in my DataList control I get no compile error yet the SelectMethod is never called. Despite some examples on the net in my searches (didn't find anything on SO) (e.g. www.srikanthtechnologies.com/blog/dotnet/aspnet45features.aspx probably an untested example) it seems the DataList Control does not inherit from System.Web.UI.WebControls.DataBoundControl like GridView does. GridView: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview(v=vs.110).aspx DataList: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datalist.itemdatabound(v=vs.110).aspx So I get no compile error when using ItemType and no call to SelectMethod. Apparently it's just not supported. Am I missing something? What other 'Data' Controls do NOT support Strong Typing?

Was it helpful?

Solution

It seems that you are completely right (so feel free to go ahead and accept your own answer, since you already did all the required research) - and as an intended workaround, use it's replacement control instead, the ListView (like all other replaced things, the DataList is still supported solely for backward compatibility, but not updated anymore in any other way)

And all other data-bound controls DO support the strongly typed model binding (even the DropDownList, and it's like).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top