Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

Formatting the Formview Control in Visual Web Developer

I am very new to creating web pages in Visual Web Developer and I need help formatting the FormView control.  When I bind my database to the form everything is lined up on the left side (labels and data) making it very unappealing.  I would like it to be displayed in a table format, but I can't figure out how to do it.  I know I can use the GridView control, but in this circumstance I need to use the FormView.  

Currently it looks something like:

Name: John Smith
Date of Birth: April 1, 2007
Sex: Male

I would like it to display the data like:

Name:                   John Smith
Date of Birth:        April 1, 2007
Sex:                      Male

Thanks for your hlep.
1 Solution
Hi Todd, this should be very easy. The FormView accepts an "ItemTemplate" and you can define an HTML table in that template like this:

<asp:FormView ID="FormView1"
      <tr><td align="right"><b>Product ID:</b></td>       <td><%# Eval("ProductID") %></td></tr>
      <tr><td align="right"><b>Product Name:</b></td>     <td><%# Eval("ProductName") %></td></tr>
      <tr><td align="right"><b>Category ID:</b></td>      <td><%# Eval("CategoryID") %></td></tr>
      <tr><td align="right"><b>Quantity Per Unit:</b></td><td><%# Eval("QuantityPerUnit") %></td></tr>
      <tr><td align="right"><b>Unit Price:</b></td>       <td><%# Eval("UnitPrice") %></td></tr>

Here's a whole article on MSDN that discusses how to implement FormView templates.

Hope that helps!

toddpotterAuthor Commented:

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now