在一系列文本框中显示LINQ列表值? [英] displaying LINQ list values in a series of textboxes?

查看:103
本文介绍了在一系列文本框中显示LINQ列表值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个预订系统,客户可以在其中输入预订ID并查看所有其他来宾,我需要帮助,在一系列文本框中显示LINQ列表中的值,我们将不胜感激.

I'm creating a booking system where a customer can enter a booking ID and see all other guests attending, I need help displaying the values from my LINQ list in a series of textboxes, any and all help would be appreciated.

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);

推荐答案

您是要在客户列表上使用ToString()还是仅仅是伪代码?

Are you trying to use a ToString() on the customers List, or is that just meant to be pseudocode?

尝试使用类似于以下内容的内容:将列表转换为字符串在C#中

Try using something similar to this: Convert a list to a string in C#

这可能包括给tblCustomer类一个ToString()覆盖,然后使用它为文本框提供所需的字符串:

This will probably include giving the tblCustomer class a ToString() override, then use that to provide the strings you need to your text boxes:

class tblCustomer
{
    public override string ToString()
    {
        return this.name;
    }
}

这篇关于在一系列文本框中显示LINQ列表值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆