Hi Rose,
Refering below article i have created sample that full fill your requirement.
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<HeaderTemplate>
<table>
<tr>
<th>
Id
</th>
<th>
Country
</th>
<th>
Chart
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblId" Text='<%# Eval("Id") %>' runat="server" />
</td>
<td>
<asp:Label ID="lblCountry" Text='<%#Eval("Country")%>' runat="server" />
</td>
<td>
<asp:Chart ID="Chart1" runat="server" Height="200px" Width="300px">
<Legends>
<asp:Legend Alignment="Center" Docking="Bottom" IsTextAutoFit="False" Name="Default"
LegendStyle="Row" />
</Legends>
<Series>
<asp:Series Name="Series1">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</form>
</body>
</html>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("Id");
dt.Columns.Add("Country");
dt.Rows.Add("1", "Finland");
dt.Rows.Add("2", "Brazil");
dt.Rows.Add("3", "USA");
this.Repeater1.DataSource = dt;
this.Repeater1.DataBind();
}
}
private void PopulateChart(Chart Chart1, string country)
{
string query = string.Format("SELECT ShipCity, COUNT(orderid) FROM ORDERS WHERE ShipCountry = '{0}' GROUP BY ShipCity", country);
DataTable dt = GetData(query);
string[] x = new string[dt.Rows.Count];
int[] y = new int[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
x[i] = dt.Rows[i][0].ToString();
y[i] = Convert.ToInt32(dt.Rows[i][1]);
}
Chart1.Series[0].Points.DataBindXY(x, y);
Chart1.Series[0].ChartType = SeriesChartType.Pie;
Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
Chart1.Legends[0].Enabled = true;
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Label lbl = e.Item.FindControl("lblCountry") as Label;
Chart chart = e.Item.FindControl("Chart1") as Chart;
PopulateChart(chart, lbl.Text.Trim());
}
}
private static DataTable GetData(string query)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand(query);
String constr = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlDataAdapter sda = new SqlDataAdapter();
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
sda.SelectCommand = cmd;
sda.Fill(dt);
con.Close();
return dt;
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim dt As New DataTable()
dt.Columns.Add("Id")
dt.Columns.Add("Country")
dt.Rows.Add("1", "Finland")
dt.Rows.Add("2", "Brazil")
dt.Rows.Add("3", "USA")
Me.Repeater1.DataSource = dt
Me.Repeater1.DataBind()
End If
End Sub
Private Sub PopulateChart(Chart1 As Chart, country As String)
Dim query As String = String.Format("SELECT ShipCity, COUNT(orderid) FROM ORDERS WHERE ShipCountry = '{0}' GROUP BY ShipCity", country)
Dim dt As DataTable = GetData(query)
Dim x As String() = New String(dt.Rows.Count - 1) {}
Dim y As Integer() = New Integer(dt.Rows.Count - 1) {}
For i As Integer = 0 To dt.Rows.Count - 1
x(i) = dt.Rows(i)(0).ToString()
y(i) = Convert.ToInt32(dt.Rows(i)(1))
Next
Chart1.Series(0).Points.DataBindXY(x, y)
Chart1.Series(0).ChartType = SeriesChartType.Pie
Chart1.ChartAreas("ChartArea1").Area3DStyle.Enable3D = True
Chart1.Legends(0).Enabled = True
End Sub
Protected Sub Repeater1_ItemDataBound(sender As Object, e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
Dim lbl As Label = TryCast(e.Item.FindControl("lblCountry"), Label)
Dim chart As Chart = TryCast(e.Item.FindControl("Chart1"), Chart)
PopulateChart(chart, lbl.Text.Trim())
End If
End Sub
Private Shared Function GetData(query As String) As DataTable
Dim dt As New DataTable()
Dim cmd As New SqlCommand(query)
Dim constr As [String] = ConfigurationManager.ConnectionStrings("ConString").ConnectionString
Dim con As New SqlConnection(constr)
Dim sda As New SqlDataAdapter()
cmd.CommandType = CommandType.Text
cmd.Connection = con
con.Open()
sda.SelectCommand = cmd
sda.Fill(dt)
con.Close()
Return dt
End Function
Output
