0

Suppose i have a data table that contains data in following structure:

Revenue-Certification-1000 Revenue-IT Exam Done-1000 Acadmics-Value1-100 Acadmics-Value23-1000 ... and so on

i have written a query that will return me a Dictionary with Key as Revenue and Academics and under these keys a generic List that contains all other values.

Now i have a requirement where i have to show a repeater control in which 1 row wouuld be Key of this Dictionary and beneath this key all the associate values.

I am not able to understand how to achieve this... a repeater under repeater or anything else. Please help to design the repeater or any other control and bind the values to it. Thanks in advance.

AChauhan
  • 207
  • 3
  • 15

1 Answers1

0

First of all, I would like to say thanks to @Aybe for his reply.

I have tried a lot and finally got what is expected.

        <div>
        <table>
            <asp:Repeater ID="Repeater1" runat="server">
                <ItemTemplate>
                    <tr>
                        <td>
                            <%#Eval("Key") %>
                            <div>
                               <asp:Repeater ID="Repeater2" runat="server">
                                   <ItemTemplate>
                                        <asp:Label runat="server" ForeColor="Red" Text='<%#Eval("MetricName") %>'></asp:Label><br />
                                       <asp:Label runat="server" ForeColor="Red" Text='<%#Eval("FiscalYeartarget") %>'></asp:Label><br />
                                   </ItemTemplate>
                               </asp:Repeater>
                            </div>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
        </table>
    </div>

and in C#- I have created a Dictionary like below:

public Dictionary<string, List<custom>> query1;
string connstr = "Data Source=(local);Initial Catalog=t;Integrated Security=True";
    string query = "SELECT * FROM [td]";
    DataTable dTable = new DataTable();

    using (SqlConnection sqlconn = new SqlConnection(connstr))
    {
        sqlconn.Open();
        SqlDataAdapter sqlda = new SqlDataAdapter(query, sqlconn);
        sqlda.Fill(dTable);

        query1 = dTable.AsEnumerable().GroupBy(x => x.Field<string>("HeaderName"))
            .ToDictionary(grp => grp.Key, x => x.Select(y => new custom()
            {
                MetricName = y.Field<string>("MetricName/KPI"),
                FiscalYeartarget = y.Field<double>("FiscalYeartarget").ToString(),
                Status = y.Field<string>("Status"),
                VTF = y.Field<double>("VTF").ToString(),
                VTF_Percent = y.Field<double>("VTF %").ToString(),
                YTDResults = y.Field<double>("YTDResults").ToString(),
                YTDTarget = y.Field<double>("YTDTarget").ToString()
            }).ToList());

        Repeater1.DataSource = query1;
        Repeater1.DataBind();

        var counter = 0;
        foreach (var x in query1)
        {
            Repeater rptr = (Repeater)Repeater1.Controls[counter].FindControl("Repeater2");
            rptr.DataSource = x.Value.ToList();
            rptr.DataBind();
            counter++;
        }
    }

and finally my custom class:

public class custom
{
    public string MetricName { get; set; }
    public string FiscalYeartarget { get; set; }
    public string YTDTarget { get; set; }
    public string YTDResults { get; set; }
    public string VTF { get; set; }
    public string VTF_Percent { get; set; }
    public string Status { get; set; }
}
AChauhan
  • 207
  • 3
  • 15