我正在从mongodb数据库中检索数据到gridview,我有一个这样的集合:
{"Name":"myName","Details":"bla bla bla","Notes":["note1","note2","note3"]}
{"Name":"myName","Details":"bla bla bla","Notes":["note1","note2"]}
{"Name":"myName","Details":"bla bla bla","Notes":["note1","note2","note3","note4"]}
我的问题是gridview readind" Notes"值System.String[]
我正在使用此代码:
Mongo mongo = new Mongo();
mongo.Connect();
var db = mongo.GetDatabase("myDB");
var collection = db.GetCollection<MyCollection>();
var entity = collection.FindAll();
BindingList<MyCollection> entity2 = new BindingList<MongoDBTest.MyCollection>();
foreach (Book item in entity.Documents)
{
entity2.Add(item);
}
GridView1.DataSource = entity2;
GridView1.DataBind();
我怎样才能正确阅读&#34; Notes&#34;值?
答案 0 :(得分:0)
我通过为我的实体Book
创建一个类来解决它:
public class Book
{
public string Name { get; set; }
public string Details { get; set; }
public List<string> Notes { get; set; }
public string NotesStr => String.Join(",", Notes);
}
现在我可以从Notes
那样检索NotesStr
Eval("NotesStr")