Filling a table on an ASP.NET page

A simple question about the population (the only column in this case). As far as this may seem an easy question, I have never participated in the front-end area, so here it is.

The layout consists of 2 columns and 8 rows. Sort of.

Name        A
LastName    B
Age         C
BirthDate   D
...

Column 1 is stable, the headers will not change if you want.

A, B, C, D are the result of database queries. So, the options I can think of are as follows:

  • Draw a 2Column - 8Row table and place the TextBoxes in the fields A, B, C, D .... Therefore, later they can be filled with query results (this option is not the most “beautiful”, because TextBoxes changes the design designed to absorb the entire page using .CSS files.

  • Install datagrid. The problem here, I think, is that some of the fields A, B, C, D need to be changed for future use of queries. And I'm not sure what the Datagrids are for.

Do I have a “good way” to solve this problem? Thanks in advance.

EDIT.

Data A, B, C, D is stored in the DataSet.

+5
source share
2 answers

, , DataGrid. , , , (-) . , ( Person) .

:

public class Person {
    public String Name { get; set; }
    public String LastName { get; set; }
    public int Age { get; set; }
    public DateTime BirthDate { get; set; }
}

Person , HTML- . TextBoxes , , Label .

<table>
    <tr><td>Name:</td><td><asp:TextBox ID="txtName" runat="server" /></td></tr>
    <tr><td>Last Name:</td><td><asp:TextBox ID="txtLastName" runat="server" /></td></tr>
    <tr><td>Age:</td><td><asp:TextBox ID="txtAge" runat="server" /></td></tr>
    <tr><td>Birthdate:</td><td><asp:TextBox ID="txtBirthDate" runat="server" /></td></tr>                  
</table>  

Person .

Person , ASP.net. :

 <asp:Repeater ID="repPeople" runat="server">
    <ItemTemplate>
        <table>
            <tr><td>Name:</td><td><asp:TextBox ID="txtName" runat="server" Text='<%# Eval("Name") %>' /></td></tr>
            <tr><td>Last Name:</td><td><asp:TextBox ID="txtLastName" runat="server" Text='<%# Eval("LastName") %>' /></td></tr>
            <tr><td>Age:</td><td><asp:TextBox ID="txtAge" runat="server" Text='<%# Eval("Age") %>' /></td></tr>
            <tr><td>Birthdate:</td><td><asp:TextBox ID="txtBirthDate" runat="server" Text='<%# String.Format("{0:d}", Eval("BirthDate")) %>' /></td></tr>                  
        </table>                
    </ItemTemplate>
</asp:Repeater>

- Person DataSource Repeater:

protected void Page_Load(object sender, EventArgs e) {

    // A simple example using Page_Load
    List<Person> people = new List<Person>();
    for (int i = 0; i < 10; i++) {
        people.Add(new Person() {Name = "Test", Age = 10, BirthDate=DateTime.Now, LastName = "Test"});
    }

    if (!IsPostBack) {
        repPeople.DataSource = people;
        repPeople.DataBind();
    }

}

.. , CSS , . , .

+7

All Articles