简体   繁体   English

C#.Net列表 <T> 在网格视图中

[英]C#.Net List<T> in Grid View

This might be a simple question, I have a List of strings which contain information about movies. 这可能是一个简单的问题,我有一个包含有关电影信息的字符串列表。 I also have a grid view of which I have binded the list of strings to as the datasource. 我也有一个网格视图,该字符串视图已将字符串列表绑定为数据源。 In the image i have attached, I have created the column headers for each of the fields. 在我所附的图像中,我为每个字段创建了列标题。 (Title, Description, AgeRating, Price). (标题,说明,AgeRating,价格)。

The problem is each item in my list stores an entire movie reference. 问题是我列表中的每个项目都存储了整个电影参考。
Eg: [0]"Interstellar;Sci-Fi Film;12;4.00" I have attached an image of the list of strings so you understand what I mean. 例如: [0]"Interstellar;Sci-Fi Film;12;4.00"我附上了字符串列表的图像,这样您就可以理解我的意思了。

How can I make it so that each item is broken down into 'title', 'Description' 'ageRating' and 'price' so that they fall under the neccessary columns 我该如何做,以便将每个项目分解为“标题”,“描述”,“年龄评分”和“价格”,以便将它们归入必要的列

eg: Title: Interstellar 例如:标题:星际
Description: Space Stuff 说明:太空物质
AgeRating: 12 年龄等级:12
Price: 5.00 价格:5.00

电影数据网格图像
字符串清单

List<string> movie = MovieM.listMovies();


        if (movie != null)
        {

            GVmovies.DataSource = movie;
            GVmovies.DataBind();
            GVmovies.BackColor = Color.LightSeaGreen;
            GVmovies.BorderColor = Color.DarkGreen;�

Instead of using a list of strings, I would create a custom object for your movie: 我将不使用字符串列表,而是为电影创建一个自定义对象:

public class Movie
{
    public string Title { get; set; }
    public string Description { get; set; }
    public int Rating { get; set; }
    public decimal Price { get; set; }
}

Set your properties for each movie and then bind a collection of these objects instead of the list of strings. 为每部电影设置属性,然后绑定这些对象的集合,而不是字符串列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM