Simple question regarding table(single column in this case) population. As much as it may seem like an easy question, I've never been involved in the front-end area, so here it goes.
The layout is 2 columns and 8 rows. Something like.
Name A
LastName B
Age C
BirthDate D
...
Column 1 are stable, "titles" if you want, that won't change.
A,B,C,D are the result of querys to a database. So, options I can think of are:
Draw a 2Column - 8Row table and place TextBoxes in A,B,C,D... fields. So later on they can be populated with the results of the query (This option is not the most "beautiful" one since TextBoxes alter the design intented to be absorved by the whole page using .CSS files.
Set a datagrid. The problem here I think is that some of the A,B,C,D fields will have to be changed for later query-usage. And I'm not sure if Datagrids are ment for that.
Is there a "good-way" for me to solve this issue? Thanks in advance.
EDIT.
A,B,C,D data is held in a DataSet.
To me, the way you're describing the data doesn't really lend itself too well for a
DataGrid
. This control works best for data that you plan to display in a standard tabular style, where the column names go across the top and then you display the row(s) of values underneath. It's also a little unclear to me if you are intending to bind one or many instances of your Object (which I will just callPerson
for now) to the UI.Let's go ahead and define that object:
To bind a single instance of
Person
to your UI, a simple HTML table should work fine. I'm usingTextBoxes
to display the values here, but if you don't need to edit them then just useLabel
s instead.It's pretty trivial at this point to bind the properties from
Person
to their respective controls on the page using the code-behind.If you wanted to use this same layout to display multiple instances of
Person
on a page, go with the ASP.net Repeater. The markup for this would look more like:In the code-behind, you just bind a collection of
Person
to theDataSource
property on theRepeater
:Note: You could accomplish a similar layout using CSS instead of tables, however the same principles apply between binding a single vs multiple objects. Just replace the table layout in this example with whatever markup you ultimately define.
There's a table control in WebForms that you should be able to populate from a DataSet see the MSDN docs: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.table.aspx