Grid View with dictionary as datasource
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 adapte开发者_运维百科rs 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.
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>
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
精彩评论