我正在创建一个预订系统,客户可以在其中输入预订 ID 并查看所有其他客人参加,我需要帮助在一系列文本框中显示我的 LINQ 列表中的值,任何和所有帮助将不胜感激。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace BookingCustomers
{
public partial class BookingGuests : System.Web.UI.Page
{
private HotelConferenceEntities datacontext = new HotelConferenceEntities();
private void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
try
{
int id = int.Parse(BookID.Text.ToString());
tblBooking booking = datacontext.tblBookings.SingleOrDefault(x => x.BookingID == id);
tblVenue venue = datacontext.tblVenues.SingleOrDefault(x => x.VenueID == booking.Venue);
List<tblCustomer> customers = new List<tblCustomer>();
List<tblBookingGuest> guests = booking.tblBookingGuests.ToList();
foreach (tblBookingGuest guest in guests)
{
tblCustomer newcust = datacontext.tblCustomers.SingleOrDefault(x=>x.CustomerID == guest.CustomerID);
customers.Add(newcust);
}
int count = customers.Count;
CustFirstName.Text = Convert.ToString(customers);