1

我使用了 adictionary<string, string>到 gridview 的早期绑定来将 Urls Text 及其 HRef 显示为键值,它就像一个魅力。但是因为我想用这个替换字典:

dictionary<string, LinkInfo>

绑定出错了!我应该处理诸如 onItemDataBound 之类的事件吗?LinkInfo结构为:

public struct LinkInfo{
    public string href;
    public bool Enabled;
}
4

1 回答 1

1

是的,您需要订阅 OnItemDataBound 事件。使用模板字段,插入带有 ID 的文字,例如“href”

在 OnItemDataBound 事件中使用

Literal _href = e.Row.FindControl("href") as Literal;  
if(_href != null)
{
  _href = ((LinkInfo)e.Row.DataItem).href;
}

编辑:我写了一篇文章进一步阐述了这个主题:http ://www.tomot.de/en-us/article/7/asp.net/gridview-overview-of-different-ways-to-bind-数据到列

于 2010-06-06T21:37:27.653 回答