我这里有这个代码:
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)
答案 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.
});