locked
Binding data from two different tables to repeater RRS feed

  • Question

  • Hi,

    I am using Repeater control. My Laout is like :

    Topic Name1:

                            Name Email

    Topic Name2:

                            Name1 Email1

                           name 2 email 2

    Topic Name3:

                            Name Email

     

    Here my data for "Topic names" is coming from one table and the name and email are coming from another table. So how can i bind data to my Repeater. I tried using dataset with two tables but it din work. Please help. How can i fetech data from two differnt tables and bind it to 1 Repeater control.


    Thanks & Regards, Bhavika

    Saturday, September 22, 2012 7:10 PM

Answers

  • First use Linq to datatables to merge results from 2 datatables to linq variable, sample code below

    var dataRows = from dataRows1 in dataTable1.AsEnumerable() join dataRows2 in dataTable2.AsEnumerable() on dataRows1.Field<int>("ID") equals dataRows2.Field<int>("ID") select dataRows1;

    DataTable dataTableLinqJoined = dataRows.CopyToDataTable();

    Once you received the results in the dararows1 or datatablelinqjoined then bind this to your repeater control like:

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

    And then use the below code to set the value to your control inside %%.

    <asp:Label ID="Label1" runat="server" Text='<%# Eval("column name") %>'></asp:Label></ItemTemplate>

    Hope this helps you.


    Mark it as helpful if so!!! thanks, Mithilesh

    Sunday, September 23, 2012 1:22 AM

All replies

  • First use Linq to datatables to merge results from 2 datatables to linq variable, sample code below

    var dataRows = from dataRows1 in dataTable1.AsEnumerable() join dataRows2 in dataTable2.AsEnumerable() on dataRows1.Field<int>("ID") equals dataRows2.Field<int>("ID") select dataRows1;

    DataTable dataTableLinqJoined = dataRows.CopyToDataTable();

    Once you received the results in the dararows1 or datatablelinqjoined then bind this to your repeater control like:

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

    And then use the below code to set the value to your control inside %%.

    <asp:Label ID="Label1" runat="server" Text='<%# Eval("column name") %>'></asp:Label></ItemTemplate>

    Hope this helps you.


    Mark it as helpful if so!!! thanks, Mithilesh

    Sunday, September 23, 2012 1:22 AM
  • Hi Bhavika18,

    You are more likely to get more efficient responses to ASP.NET issues at http://forums.asp.net where you can contact ASP.NET experts.
     


    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us

    Friday, September 28, 2012 3:28 AM