External XML data to gridview - asp.net

I´m trying to get data (link) from an public XML file to my gridview.
I´m trying following, but can't get it done. Anyone can help me on that?
<body>
<form id="form1" runat="server">
<div>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="http://weather.aero/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=lebl&hoursBeforeNow=5"> </asp:XmlDataSource>
<asp:GridView ID="GridView1" runat="server" DataSourceID="XmlDataSource1">
</asp:GridView>
</div>
</form>
</body>
Any help would be very appreciated.
Thanks in advance for any help.
RU

You will have to parse the XML anyway so try this
Markup
<asp:GridView ID="WeatherList" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Latitude" HeaderText="Latitude" />
<asp:BoundField DataField="WindDirectionSpeed" HeaderText="Wind Speed(kms)" />
</Columns>
</asp:GridView>
Code-behind
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindWeatherGrid();
}
}
private void BindWeatherGrid()
{
var url = "http://weather.aero/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=lebl&hoursBeforeNow=5";
XDocument doc = XDocument.Load(url);
var metars = from wthr in doc.Descendants("METAR")
select new Metar()
{
Latitude = (string)wthr.Element("latitude"),
WindDirectionSpeed = (string)wthr.Element("wind_speed_kt")
};
WeatherList.DataSource = metars;
WeatherList.DataBind();
}
Namespaces used
using System.Linq;
using System.Xml.Linq;
Helper Class
public class Metar
{
public string Latitude { get; set; }
public string WindDirectionSpeed { get; set; }
}

Related

ASP.NET Error when binding a GridView to a List of Objects?

Error Message:
The data source for GridView with id 'FormProprietari' did not have
any properties or attributes from which to generate columns. Ensure
that your data source has content.
I have a ASP.NEt application in which I try to bind a GridView to a List<T> objects which from what I can tell on the net it should be possible.
This is my GridView:
<asp:GridView ID="FormProprietari" runat="server">
<Columns>
<asp:TemplateField >
<ItemTemplate>
<%#((Lab_TAP_web.Proprietar)Container.DataItem).NumeProprietar%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<%#((Lab_TAP_web.Proprietar)Container.DataItem).PrenumeProprietar%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<%#((Lab_TAP_web.Proprietar)Container.DataItem).ProprietarID%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
And this is the function in which I add a new object of the Proprietar class I defined to the database then rebind the gridview to show it, I should mention that intially the database is empty and so is the gridview i,e it doesn't show up.
protected void Button2_Click(object sender, EventArgs e)
{
var Nume = TBNumeProprietar.Text;
var Prenume = TBPreNumeProprietar.Text;
MyCars db = DBSilo.db;
Proprietar newOwner = new Proprietar();
newOwner.NumeProprietar = Nume;
newOwner.PrenumeProprietar = Prenume;
newOwner.ProprietarID = (db.Proprietari.Count() + 1);
//newOwner.ProprietarID = 1;
db.Proprietari.InsertOnSubmit(newOwner);
db.SubmitChanges();
try
{
FormProprietari.DataSource = db.Proprietari.ToList();
}
catch (Exception)
{
throw;
}
FormProprietari.DataBind();
}
The problem being that I checked the List<Proprietar> which is the data source with breakpoints and the list always contains a Proprietar object.
Does anyone have a idea what I did wrong?
Moved from comment to Answer.
Please make sure you have getter and setter for each property of Proprietar class like this -
public class Proprietar
{
public string NumeProprietar { get; set; }
public string PrenumeProprietar { get; set; }
public int ProprietarID { get; set; }
}

How to Combine TemplateFields in ASP.Net GridView?

Everyone.
I have a question when combining cells in GridView. I konw how to combine BoundField cells, but I do not know how to combine TemplateField cells in asp.net GridView.
EDIT:
Perhaps I did not make my question clearly and I am sorry about that. My question is that I use GridView to bind data from db and There is a field named UserName, one user has several records in the db, so I want to combine UserName in one cell(i can combine it correctly). In the same way, I want to do some operation to this user such as Add, Delete. So i put these operations into TemplateField, but i do not konw how to combine TemplateField like BoundField. I have a low reputation, so i can not post images
Any good ideas?
Sorry for my poor english! Thanks in advance.
There isn't a way to merge/combine fields. I think you misunderstood the BoundFields/TemplateField. However you can use Eval() and Bind() to show/bind one or more expression into single cell//column..
Read MSDN articles:
BoundField
TemplateField
EDIT:
#loren : There is a field named UserName, one user has several records
in the db.
I guess you need to use "nested" grid or you may also use any data control (formview, detail view or ListView).
Here is demo that shows how to bind nested data controls.
I've define two classes - Contact, Info
public class Contact
{
public string Address{get;set;}
public string Phone {get;set;}
}
public class Info
{
public string UserName {get;set;}
private List<Contact> _addr=new List<Contact>();
public List<Contact> Address
{
get { return _addr; }
set { _addr = value; }
}
}
In .aspx page (Markup),
<asp:GridView
ID="GridView1"
runat="server"
AutoGenerateColumns="false"
onrowdatabound="GridView1_RowDataBound"
>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<p>
Username :
<asp:Literal
ID="UserName"
runat="server"
Text='<%#Eval("UserName") %>'
>
</asp:Literal>
</p>
<asp:GridView
ID="GridView2"
runat="server"
AutoGenerateColumns="false"
>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<p>Phone :
<asp:TextBox
runat="server"
ID="txtDetail"
Text='<%#Bind("Phone") %>'
></asp:TextBox>
</p>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and in code-behind (aspx.cs),
List<Info> info;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
info = new List<Info>()
{
new Info()
{
UserName="User1",
Address =
{
new Contact() { Phone="2929927", Address="Address1"},
new Contact() { Phone="2929928", Address="Address2"},
}
},
new Info()
{
UserName="User2",
Address =
{
new Contact() { Phone="2929929", Address="Address3"},
new Contact() { Phone="2929930", Address="Address4"},
}
},
};
GridView1.DataSource = info;
GridView1.DataBind();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Literal username=(Literal)e.Row.FindControl("UserName");
GridView view=(GridView)e.Row.FindControl("GridView2");
if (view != null)
{
var result = from ele in info
from add in ele.Address
where ele.UserName == username.Text
select add;
view.DataSource = result;
view.DataBind();
}
}
If possible, you can update the source type.
For example, if you an object data source and a model like this :
[DataObject]
public class MyOds{
[DataObjectMethod(DataObjectMethodType.Select)]
public ICollection<MyModel> GetMyModels()
{
var result = new ListMyModel();
Populate(result); // load model with any method of you choice
return result;
}
}
public class MyModel{
public string Address { get; set; }
public string City { get; set; }
public string Country { get; set; }
public string FullAddress {
get
{
return string.Format("{0} - {1} - {2}", Address, City, Country);
}
}
}
Note the FullAddress property. The idea is to build, for the view, properties easy to exploit. The ASPX can looks like this :
<asp:TemplateField HeaderText="Header">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text="Label">
<%# Eval("FullAddress")%>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
you can use Eval as bellow
<asp:TemplateField HeaderText="Header">
<ItemTemplate>
<asp:TextBox runat="server" ID="txt1" Text='<%#Bind("Phone") %>'></asp:TextBox>
<asp:TextBox runat="server" ID="txt2" Text='<%#Bind("Address") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>

GridView event raise unexpectedly after postback

Consider this Asp.net page code:
<head runat="server">
<title></title>
<script type="text/javascript">
function showhide(master, detail) {
var src = $(master).children()[0].src;
if (src.endsWith("plus.png"))
src = src.replace('plus.png', 'minus.png');
else
src = src.replace('minus.png', 'plus.png');
$(master).children()[0].src = src;
$(detail).slideToggle("normal");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/scripts/jquery-1.6.2.min.js" ScriptMode="Release" />
</Scripts>
</asp:ScriptManager>
<div>
<asp:SqlDataSource ID="sqlDsCustomers" runat="server" ConnectionString="<%$ ConnectionStrings:Northwind %>"
SelectCommand="SELECT [Customers].[CustomerID], [Customers].[CompanyName], COUNT([OrderID]) TotalOrders
FROM [Customers] INNER JOIN [Orders] ON [Customers].[CustomerID]=[Orders].[CustomerID]
Group By [Customers].[CustomerID], [Customers].[CompanyName]">
</asp:SqlDataSource>
<asp:GridView Width="100%" AllowPaging="True" ID="gvCustomers" AutoGenerateColumns="False"
DataSourceID="sqlDsCustomers" runat="server" ShowHeader="False" OnRowCreated="gvCustomers_RowCreated">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<div class="group" id='<%#String.Format("customer{0}",Container.DataItemIndex) %>'
onclick='showhide(<%#String.Format("\"#customer{0}\"",Container.DataItemIndex) %>,<%#String.Format("\"#order{0}\"",Container.DataItemIndex) %>)'>
<asp:Image ID="imgCollapsible" CssClass="first" ImageUrl="~/Assets/img/plus.png"
Style="margin-right: 5px;" runat="server" /><span class="header">
<%#Eval("CustomerID")%>
:
<%#Eval("CompanyName")%>
(<%#Eval("TotalOrders")%>Orders) </span>
</div>
<div id='<%#String.Format("order{0}",Container.DataItemIndex) %>' class="order">
<asp:GridView AutoGenerateColumns="false" CssClass="grid" ID="ddd" runat="server"
ShowHeader="true" EnableViewState="false">
<RowStyle CssClass="row" />
<AlternatingRowStyle CssClass="altrow" />
<Columns>
<asp:TemplateField ItemStyle-CssClass="rownum">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Order ID" DataField="OrderID" ItemStyle-Width="80px" />
<asp:BoundField HeaderText="Date Ordered" DataField="OrderDate" DataFormatString="{0:MM/dd/yyyy}"
ItemStyle-Width="100px" />
<asp:BoundField HeaderText="Date Required" DataField="RequiredDate" DataFormatString="{0:MM/dd/yyyy}"
ItemStyle-Width="110px" />
<asp:BoundField HeaderText="Freight" DataField="Freight" DataFormatString="{0:c}"
ItemStyle-Width="50px" ItemStyle-HorizontalAlign="Right" />
<asp:BoundField HeaderText="Date Shipped" DataField="ShippedDate" DataFormatString="{0:MM/dd/yyyy}"
ItemStyle-Width="100px" />
</Columns>
</asp:GridView>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</form>
and the code behind:
protected void Page_Load(object sender, EventArgs e)
{
}
protected void gvCustomers_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string custID = ((DataRowView)e.Row.DataItem)["CustomerID"].ToString();
using (DataClassesDataContext dc=new DataClassesDataContext())
{
List<Order> ord = (from o in dc.Orders
where o.CustomerID == custID.Trim()
select o).ToList();
GridView ctrl = e.Row.FindControl("ddd") as GridView;
ctrl.DataSource = ord;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
the problem is when I Click on Button1 to redirect to another page gvCustomers_RowCreated raise and I get Null reference error.Why this event raised after postback?
EDIT 1):
I removed SqlDataSource and bind GridView in the code behind like this:
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
using (DataClassesDataContext dc=new DataClassesDataContext())
{
var query = dc.ExecuteQuery<clsRetern>("SELECT [Customers].[CustomerID], [Customers].[CompanyName], COUNT([OrderID]) TotalOrders FROM [Customers] INNER JOIN [Orders] ON [Customers].[CustomerID]=[Orders].[CustomerID] Group By [Customers].[CustomerID], [Customers].[CompanyName]").ToList();
List<clsRetern> ret = new List<clsRetern>();
foreach (var item in query)
{
clsRetern r = new clsRetern();
r.CompanyName = item.CompanyName;
r.CustomerID = item.CustomerID;
r.TotalOrders = item.TotalOrders;
ret.Add(r);
}
gvCustomers.DataSource = ret;
gvCustomers.DataBind();
}
}
}
protected void gvCustomers_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string custID = ((clsRetern)e.Row.DataItem).CustomerID.Trim();
using (DataClassesDataContext dc=new DataClassesDataContext())
{
List<Order> ord = (from o in dc.Orders
where o.CustomerID == custID.Trim()
select o).ToList();
GridView ctrl = e.Row.FindControl("ddd") as GridView;
ctrl.DataSource = ord;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx",true);
}
}
public class clsRetern
{
public string CustomerID { get; set; }
public string CompanyName { get; set; }
public int TotalOrders { get; set; }
}
I tried Response.Redirect("Default.aspx"); but the problem still remains.
If you understand ASP.NET page model then this question should not come to you. Every time request goes to ASP.NET page, a new page object is created along with entire control tree and the state is managed using view-state in post-back scenarios. So in your case, whenever post-back happens, a new page and grid-view is created. The data for the gid-view would be persisted in thew view-state and grid would be bound to that data.
The RowCreated event is raised whenever grid row is created regardless of whether DataBind is explicitly called or not. The intent of the event is so that one can tweak with UI (grid-view cells) - e.g. some controls can be pushed into grid-view cells if required. The same should happen regardless of post-back scenario other wise those dynamic controls will not get created. Typically, these controls will restore their state using view-state and your get your grid-view UI (control tree) back as it was in first page cycle.
Thats because even if you fire Response.Redirect, the Page_Load event would still be raised and if your GridView binding code is not inside !IsPostBack, that code will be hit.
Try this.
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
//bind gridview here
}
}
catch (Exception exception)
{
//Elmah.ErrorSignal.FromCurrentContext().Raise(exception);
}
}
Savvy?
Add EnableViewState=False to the page directive to prevent "RowCreated" running on every post back.

Append empty text box Rows to a grid

I have a grid with two columns first column with check box and second column with text box. I have a add and save button down the grid.Can you please tell how to obtain if i click add button i need to append one more row to the grid with empty text box and check box so that i can type and click save
need to do possibly without java script
If I am getting you correctly you want something like below
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>
<!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="grdDemo" runat="server" AutoGenerateColumns="False" EnableModelValidation="True">
<Columns>
<asp:TemplateField HeaderText="CheckBox">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("IsCheckBox") %>' Enabled="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="TextBox">
<ItemTemplate>
<asp:TextBox ID="Label1" runat="server" Text='<%# Bind("IsTextBox") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Save" />
</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.Web.Caching;
public partial class Default5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
grdDemo.DataSource = new Demo().GetData();
grdDemo.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
var list = new Demo().GetData();
list.Add(new Demo() {IsCheckBox = false, IsTextBox = ""});
Cache["list"] = list;
grdDemo.DataSource = list;
grdDemo.DataBind();
}
}
public class Demo
{
public bool IsCheckBox { get; set; }
public string IsTextBox { get; set; }
public List<Demo> GetData()
{
if (HttpContext.Current.Cache["list"] == null)
{
List<Demo> list = new List<Demo>()
{
new Demo(){IsCheckBox=true,IsTextBox = "text1"},
new Demo(){IsCheckBox=false,IsTextBox = "text2"},
};
return list;
}
return (List<Demo>)HttpContext.Current.Cache["list"];
}
}

Databind List of Dictionnary into a GridView

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
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();

Resources