Which is the best control/approach in ASP.NET 4 to bind data from single record, which is fetched from sql server? I have some page to display text, so I need labels like title, date of publication, content and so on – single label for each data. Of course I can use ListView or Repeater, but I wonder if there’s some other way.
Thanks in advance
You could use the DetailsView, which is designed to display a single record (though it’s usually used in a master-details scenario). DetailsView can use SqlDatasource.
Trivial example:
The above example creates a DetailsView based on the SelectCommnad of the SqlDataSource. In the implementation above, since AutoGenerateRows is set to true the control will render the data. However, you can also specify the fields explicitly, and have different fields you can choose from (BoundField, ButtonField, CheckBoxField, etc).
DetailsView Class