我使用了dictionary<string, string>与网格视图的早期绑定来显示Urls文本和它的HRef作为键值,它的工作原理就像一种魅力。但既然我想用这本字典来代替它:
dictionary<string, LinkInfo>装订出错了!我应该处理一些像onItemDataBound之类的事件吗?LinkInfo结构是:
public struct LinkInfo{
public string href;
public bool Enabled;
}发布于 2010-06-06 21:37:27
是的,您需要对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-data-to-columns
https://stackoverflow.com/questions/2985554
复制相似问题