Set the AutoGenerateColumns property of the DataGrid to False.Sample code below
VB.NET
<asp:DataGrid AutoGenerateColumns=False id='DataGrid1' runat='server'>
<Columns >
<asp:TemplateColumn HeaderText='HashTable'>
<ItemTemplate>
<%# Container.DataItem.Key %> <br>
<%# Container.DataItem.Value %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
’In Page_Load
Dim ht As New Hashtable()
ht.Add('emp1', 'A')
ht.Add('emp2', 'B')
ht.Add('emp3', 'C')
DataGrid1.DataSource = ht
DataGrid1.DataBind()
C#
<asp:DataGrid AutoGenerateColumns=False id='DataGrid1' runat='server'>
<Columns >
<asp:TemplateColumn HeaderText='HashTable'>
<ItemTemplate>
<%# ((DictionaryEntry)Container.DataItem).Key %><br>
<%# ((DictionaryEntry)Container.DataItem).Value %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
//In Page_Load
Hashtable ht = new Hashtable();
ht.Add ('emp1', 'A');
ht.Add ('emp2', 'B');
ht.Add ('emp3', 'C');
DataGrid1.DataSource = ht;
DataGrid1.DataBind();
Share with