0

我有一个嵌套的gridview,父gridview 使用数据键将数据绑定到子gridview。

到目前为止,我的父网格视图中只有一列。所以我通过以下方式将数据绑定到父 Gridview。

GridView1.DataSource = id.Select(oid1 => new { id1 }).ToList(); // id1 is the datakey

但是,现在我有两列,即“ID”和“ID 计数”。

如果我将值存储在列表中并尝试在网格视图中显示它们。它无法将数据绑定到子网格视图。我认为是因为它无法识别数据密钥。尽管我非常精确地指定了名称。

我通过以下方式将值存储在列表和 Gridview 中。

public class results
    {
        public string id1 { get; set; }
        public int count { get; set; }

    }

List<results> res = new List<results>();
results r= new results();
r.id1="XXSSDD";
r.count=5;
res.Add(r);
Gridview1.DataSource=res;
Gridview1.DataBind();

此外, id 存储在哈希集中,我想保持这种方式。

谢谢。

请让我知道,如果你有任何问题。

4

0 回答 0