我正在尝试从文件中获取数据并使用它创建表。该程序已经运行,它接收用户输入的信息并将其插入MDF文件。我可以从文件中获取信息并使用它创建一个字符串并显示字符串。但我想格式化它,使它显示在一个表中,而不是将每个记录显示为列表中的字符串。这是我从数据库中获取信息的代码,以及我用来将其显示为字符串列表的代码。
这是我用来从数据库中获取信息并用它创建一个字符串的方法。
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
// The Model that has all the getter and setter methods for the rentals
namespace SimpleForm.Models
{
public partial class Rentals
{
public int Id { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public string MovieTitle { get; set; }
public string MemberIDNumb { get; set; }
public string RentalLength { get; set; }
public string IsMember { get; set; }
public string MovieFormat { get; set; }
//String that is returned in the view page.
//Shows all the information from each rental
public string InfoString
{
get
{
return LastName + "," + FirstName + "," + IsMember + "," + MemberIDNumb + "," + MovieTitle + "," + MovieFormat + "," + RentalLength;
}
}
}
}
这是在加载页面时显示信息的代码。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="view-
rentals.aspx.cs" Inherits="SimpleForm.viewrentals" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table id="RentalsInfo">
<tr>
<td>Last Name</td>
<td>First Name</td>
<td>Member?</td>
<td>Member ID</td>
<td>Movie Title</td>
<td>Movie Format</td>
<td>Rental Length</td>
</tr>
</table>
<br />
<br />
<asp:Label runat="server" ID="lblResults"></asp:Label>
</div>
</form>
</body>
</html>