ASP.NET ToList<>把bool扔到字符串

时间:2016-08-16 19:44:56

标签: c# asp.net

我这里有这个代码:

GridView gv = new GridView();
            gv.DataSource = db.Data.ToList().Where(model => model.closed == false);

这很有效。我想知道是否可以将我的列表中的项目从bool转换为字符串?

之类的东西
gv.DataSource = db.Data.ToList().Where(model => model.closed == false).Cast(convert model.closed to string)

1 个答案:

答案 0 :(得分:2)

将结果投射到anonymous type并在那里进行转换。

GridView gv = new GridView();
gv.DataSource = db.Data.ToList().Where(model => !model.closed)
    .Select(m => new
    {
        Closed = Convert.ToString(m.Closed),
        //... Rest of the fields. 
    });