1

So, I am kinda new to ASP.net development still, and I already don't like the stock ASP.net controls for displaying my database query results in table format. (I.e. I would much rather handle the HTML myself and so would the designer!)

So my question is: What is the best and most secure practice for doing this without using ASP.net controls? So far my only idea involves populating my query result during the Page_Load event and then exposing a DataTable through a getter to the *.aspx page. From there I think I could just iterate with a foreach loop and craft my table as I see fit.

4 Answers 4

4

I believe you're looking for a <Repeater> control. It contains some functionality similar to the GridViews, but allows you hand-craft all of the HTML for the Header, Item, and Footers yourself. Simply call the databinding code as you would for a gridview, and change the ASPX page to suit your exact HTML needs.

http://msdn.microsoft.com/en-us/magazine/cc163780.aspx

Sign up to request clarification or add additional context in comments.

Comments

3

The successor to the repeater is the ListView, which will also help you handcraft your HTML.

Comments

1

If you're more interested in hand Coding your HTML, it might be worth looking at the ASP.NET MVC project. You get a little more control over things than standard WebForms.

As an aside, plugging data access code in the Page_Load is never a good idea. It ties your presentation too much to your data code. Have a look at either the MVC as suggested above which applies a standard design pattern to separate concerns, or do a google search for "ASP.NET nTier" or something similar. It might take a little longer to get a site up and running, but it will save you pain in the long run.

Comments

1

three options:

  1. learn to use the existing controls like GridView; with proper CSS they can look quite nice, since they just generate HTML on the client side

  2. generate your HTML using templates or StringBuilder and put it in a Literal control on your web page

  3. buy a third-party library that has controls that you do like

number 1 is the 'best' option for asp.net in the long term because you will actually master the controls that everyone else uses; option 2 is tedious; option 3 is a quick fix and may be expensive

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.