How do ASP.Net controls read from their data sources?

I need to display information on my pages so that none of the standard ASP.net controls are supported. To do this, I created my own controls and had to reproduce some of the features of ASP.Net controls, in particular their ability to communicate with several different data sources.

According to the documentation, controls can communicate with any data source that supports IEnumerable, ICollection, or IListSource. Now I know that you can directly bind controls to SQLDataReader, but I cannot decide which interface corresponds to the class, which allows this to work. IIRC implements iEnumerable, but to enumerate columns, not rows.

I want my own objects to be able to consume these data sources, and I have a way to do this (using reflection for dynamic access to properties, etc.), but since the .Net infrastructure already does this, I hope there is an object already being part of the framework, eliminating the need for me to roll. Questions:

1) What condition does SQLDataReader meet to allow it to be used as a data source for ASP.Net controls? 2) Is there a class that can iterate over allowed ASP.Net data sources in turn, avoiding the need to roll my own?

+4
source share
1 answer

I don’t know if this is the exact answer to your question, but you can iterate over SqlDataReader using the DbDataRecord class (in which case IEnumerable iterates through the lines), for example. (VB.NET):

For Each rec As Data.Common.DbDataRecord In MyReader 'access fields by rec(ordinal) or rec(FieldName) Next 
+1
source

Source: https://habr.com/ru/post/1481615/


All Articles