Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Very Simple Question 1

Status
Not open for further replies.

barrylowe

Programmer
Nov 6, 2001
188
GB
What is the easiest way to display the contents of a database record on an ASP.net page using Visual Studio 2005?

The page merely needs to display the data as read-only text.

In the past I have used a series of labels which were populated using a datareader. The datareader was filled using the ExecuteReader method of a SqlCommand object.

This did the job perfectly well but the code was quite lengthy moving through each field in the datareader and writing to the appropriate label.

I was just wondering if there was a simpler way of doing what must be a very common task?
 
define easy.

does it need to to be easy to test? if so how?
F5 debugging? if so then fetching the data by hand and binding the data to a formview is still easy and can all be done within the page behind.
unit testing? then you need to separate concerns and introduce a model/view/presenter framework and possibly a repository object. you will also want to build these objects in a separate assembly project and reference this "core" project in the website project. this is more coding upfront, but easier to maintain moving forward. you will also need a 3rd project(assemebly) for unit testing.

does it need to be adaptable to changing user requests?
(logging, auditing, conditional business logic)
if so then you will want a model/view/presenter framework and possibly a repository object.

personally I have grown tired of the webforms model and how tightly coupled webforms are to the http request. For that reason I am moving towards Castle MonoRail and MS MVC. here I am not burdened with code behind, page life cycle, view state and all the other baggage of webforms. I have a clean separation of concerns and I can easily integrate a unit testing framework like nunit or mbunit to test each object in the system.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I mean easy as in simple and quick to do.

The page is merely a data display, so there will be minimal testing involved and is therefore not a consideration.

The reason I asked the question in the first place is that everytime I see a microsoft demo they are knocking things together in no time at all using wizards and drag and drop functionality. Whereas when I sit down to do something I end up hacking code for hours on end.

 
But is a repeater not used to display multiple records?

I only want to show the fields for a single record. Kind of like the page you would go to when drilling down from a list.
 
You can still use a repeater if only for one record. I suggested that because it is easy to impliment and you have a lot of control over what html renders. And binding is as simple as using only one databind method.

In .NET 2.0 and above, textboxes are not bindable. In your case, I had to build pages exactly like that. I used to simply bind to a bunch of textboxes. However, in the newer frameworks, textboxes are not bindable for some reason. So, you would have to get a datatable, loop through, get each value and place in the textbox.text value. That is why I suggested using a repeater, event though it is for only one row. And it is scalable in case they decide to view more than one row at a time.
 
The reason I asked the question in the first place is that everytime I see a microsoft demo they are knocking things together in no time at all using wizards and drag and drop functionality.
yes, but that is only one way to look at the problem.
this works for quick demos, or "my website" websites, but this is not the way to maintain medium or large applications, not matter how "simple" the form is.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top