Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在一系列文本框中显示LINQ列表值?_C#_Linq - Fatal编程技术网

C# 在一系列文本框中显示LINQ列表值?

C# 在一系列文本框中显示LINQ列表值?,c#,linq,C#,Linq,我正在创建一个预订系统,客户可以输入预订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; nam

我正在创建一个预订系统,客户可以输入预订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);
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControl;
使用System.Data.SqlClient;
命名空间预订客户
{
公共部分类预订来宾:System.Web.UI.Page
{
private HotelConferenceEntities datacontext=新建HotelConferenceEntities();
私有无效页面加载(对象发送方,事件参数e)
{
如果(第IsPostBack页)
{
尝试
{
int id=int.Parse(BookID.Text.ToString());
tblBooking booking=datacontext.tblBookings.SingleOrDefault(x=>x.BookingID==id);
tblVenue场馆=datacontext.tblVenues.SingleOrDefault(x=>x.VenueID==booking.venue);
列出客户=新列表();
List guests=booking.tblBookingGuests.ToList();
foreach(tblBookingGuest in guests)
{
tblCustomer newcust=datacontext.tblCustomers.SingleOrDefault(x=>x.CustomerID==guest.CustomerID);
customers.Add(newcust);
}
int count=customers.count;
CustFirstName.Text=Convert.ToString(客户);

不确定您要查找的结果是什么-它们必须是文本框吗-意思是用户可编辑的?如果不是,您可以使用单个标签,并将每个名称附加在后面,可以是逗号分隔的字符串,也可以用“”分隔在两者之间。可能不太漂亮,但它会起作用。与其将“customers”作为tblCustomer的列表,不如将其设置为列表,并在该循环中添加ToString方法,然后对文本框执行string.join

List<string> customers = new List<string>();
foreach (tblBookingGuest guest in guests)
{
   tblCustomer newCust = datacontext.tblCustomers.SingleOrDefault(x=>x.CustomerID == guest.CustomerID);
   customers.Add(GetCustomerString(newCust));
}
CustFirstName.Text = string.Join("</BR>", customers.ToArray);

您是在尝试使用客户列表上的ToString(),还是这只是一个伪代码

尝试使用类似的方法:

这可能包括为tblCustomer类提供ToString()重写,然后使用该重写为文本框提供所需的字符串:

class tblCustomer
{
    public override string ToString()
    {
        return this.name;
    }
}
可能重复的
class tblCustomer
{
    public override string ToString()
    {
        return this.name;
    }
}