tags:

views:

27

answers:

2

Hi,

Please help me out... I need to set a dictionary as datasource to a GridView. The dictionary contains objects with for example the attributes start and finish. I have only found information about connecting datasets, resultsets, sql adapters and so on to GridViews.

The GridView im trying to present my dictionary with, should also be editable, but I guess the NO1 issue is to just connect it.

+1  A: 

If you just set it as the datasource and set autegenreate columns to true of the gridview it will work just fine. If you want to bind the columns explicitly then you bind them to the Key and Value properties. e.g.:

<asp:GridView runat="server" ID="MyGridView" AutoGenerateColumns="false">
     <Columns>
         <asp:BoundField DataField="Key" />
         <asp:BoundField DataField="Value" />
     </Columns>            
</asp:GridView>
Ben Robinson
+1  A: 

Just set the Datasource property to your Dictionary object.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.aspx#binding_to_data

Barry