2010-06-06 54 views
1

我已經使用了一個dictionary<string, string>的早期綁定到一個gridview來顯示Urls文本及其HRef作爲鍵值,它的作用就像一個魅力。 但因爲我想更換字典與此一:如何將複雜的字典綁定到asp.net中的Gridview?

dictionary<string, LinkInfo> 

結合順心!我應該處理一些像onItemDataBound之類的事件嗎? 和LinkInfo結構爲:

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

回答

1

是的,你需要subsribe到OnItemDataBound事件。使用模板字段中插入一個文本中包含「HREF」

在OnItemDataBound事件的ID使用

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

+0

我不想使用模板字段,但你告訴我這個代碼的方式。謝謝 – Mehdi 2010-06-07 07:08:22