Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4341672
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:30:58+00:00 2026-05-21T11:30:58+00:00

I’d like to bind a List of Dictionary to a GridView. var liste =

  • 0

I’d like to bind a List of Dictionary to a GridView.

var liste = new List<Dictionary<string, string>>();
var dictionary = new Dictionary<string,string>();
dictionary["Id"] = "111";
dictionary["Description"] = "text to show";
dictionary["OtherInfo"] = "other text";
liste.Add(dictionary);
gvClients.DataSource = liste;
gvClients.DataBind();

The code in the aspx :

<asp:GridView ID="gvClients" runat="server" AutoGenerateColumns="true" GridLines="None"
  AllowPaging="True" CssClass="gridview" AlternatingRowStyle-CssClass="alt" Width="80%">
<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
  <Columns>
    <asp:TemplateField HeaderText="PropertyName">
      <ItemTemplate>
        <asp:Label ID="Label1" runat="server" Text='<%# Eval("Description") %>'></asp:Label>
      </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="PropertyName">
      <ItemTemplate>
        <asp:Label ID="Label2" runat="server" Text='<%# Eval("OtherInfo") %>'></asp:Label>
      </ItemTemplate>
    </asp:TemplateField>
  </Columns>
</asp:GridView>

How can I bind the GridView to that Object (or a System.Collections.HashTable).

edit

The geek’s solution for Dictionary work but not for HashTable, is there a solution ?

var liste = new List<System.Collections.Hashtable>();
var table = new System.Collections.Hashtable();
table["Denomination"] = "a";
table["Denomination2"] = "an";
liste.Add(table);

var result = liste.Select(map => new
{
    IdClient = map["Denomination"],
    Denomination = map["Denomination2"]
}).ToList();

gvClients.DataSource = result;
gvClients.DataBind();

I’ve this error :

The data source for GridView with id 'gvClients' did not have any properties or attributes from which to generate columns.

When I modify the mapping like this :

var result = liste.Select(map => new
{
    IdClient = map["Denomination"],
    Denomination = map["Denomination2"],
    Test = "test"
}).ToList();

It will show only the Test property.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T11:30:59+00:00Added an answer on May 21, 2026 at 11:30 am

    Check out the following code.

    <%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head runat="server">
            <title></title>
        </head>
        <body>
            <form id="form1" runat="server">
            <div>
                <asp:GridView ID="gvClients" runat="server" AutoGenerateColumns="false" GridLines="None"
                    CssClass="gridview" AlternatingRowStyle-CssClass="alt" Width="80%">
                    <AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
                    <Columns>
                        <asp:BoundField DataField="Key" />
                        <asp:BoundField DataField="Value" />
                    </Columns>
                </asp:GridView>
            </div>
            </form>
        </body>
        </html>
    
    
    
    
    using System;
            using System.Collections.Generic;
            using System.Linq;
            using System.Web;
            using System.Web.UI;
            using System.Web.UI.WebControls;
            using System.Collections.Specialized;
    
            public partial class _Default : System.Web.UI.Page
            {
    
    
                protected void Page_Load(object sender, EventArgs e)
                {
                    if (!IsPostBack)
                    {
                        var liste = new List<Dictionary<string, string>>();
                        var dictionary = new Dictionary<string, string>();
                        dictionary["PropertyName"] = "text to show";
                        var dictionary2 = new Dictionary<string, string>();
                        dictionary2["PropertyName"] = "text to show1";
                        liste.Add(dictionary2);
                        liste.Add(dictionary);
                        var result = liste.SelectMany(x => x);
                        gvClients.DataSource = result;
                        gvClients.DataBind();
                    }
    
                }
            } 
    

    Edit

    I have edited the code as per your requirements.Please try this code and let me know if you experience any problems .

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:GridView ID="gvClients" runat="server" AutoGenerateColumns="true" GridLines="None"
                CssClass="gridview" AlternatingRowStyle-CssClass="alt" Width="80%">
                <AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
            <Columns>
                    <asp:TemplateField HeaderText="Description">
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("Description") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="OtherInfo">
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Eval("OtherInfo") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </div>
        </form>
    </body>
    </html>
    
    
    
    
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    public class Client
    {
        public string ID { get; set; }
        public string Description { get; set; }
        public string OtherInfo { get; set; }
    }
    public partial class Default3 : System.Web.UI.Page
    {
      List<Client> list=new List<Client>();
        protected void Page_Load(object sender, EventArgs e)
        {
    
            if (!IsPostBack)
            {
                var liste = new List<Dictionary<string, string>>();
                var dictionary = new Dictionary<string, string>();
                dictionary["ID"] = "111";
                dictionary["Description"] = "XYZ";
                dictionary["OtherInfo"] = "Addd";
                liste.Add(dictionary);
    
    
                var result = liste.Select(map => new Client
                {
                    ID = map["ID"],
                    Description = map["Description"],
                    OtherInfo = map["OtherInfo"]
                }).ToList();
    
                gvClients.DataSource = result;
                gvClients.DataBind();
    
            }
    
        }
    }
    

    EDITII

    If you want to use Hashtable then do the following

    Create a new class named Client (what ever you want)

    public class Client
    {
        public string IdClient  { get; set; }
        public string Denomination  { get; set; }
    }
    

    and then query the list as follows

     var liste = new List<Hashtable>();
                var table = new Hashtable();
                table["Denomination"] = "a";
                table["Denomination2"] = "an";
                liste.Add(table);
    
                var result = liste.Select(map => new Client()
                {
                    IdClient = map["Denomination"].ToString(),
                    Denomination = map["Denomination2"].ToString()
                });
    
                gvClients.DataSource = result;
                gvClients.DataBind();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Specifically, suppose I start with the string string =hello \'i am \' me And
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.