How to associate a complex dictionary with Gridview in asp.net?

I used early binding with gridview to show Urls Text and its HRef as a key value, and it works like a charm. But since I want to replace the dictionary with the following: dictionary<string, string>

dictionary<string, LinkInfo>

binding goes wrong! Should I handle some events like onItemDataBound or something else? and LinkInfo structure :

public struct LinkInfo{
    public string href;
    public bool Enabled;
}
+1
source share
1 answer

Yes, you need to sign the OnItemDataBound event. Use the template field, insert a literal with an identifier of type "href"

In the OnItemDataBound event use

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

+1

Source: https://habr.com/ru/post/1767014/


All Articles