0

In my application I need to fetch items from 2 SharePoint lists(ListA & ListB) as a listitem-collection and then I need to show items from ListA if the items in ListB matchs (ListA.empid == ListB.empid).

var iPs = AListItem.AsEnumerable()
                   .Select(r => r.FieldValues["EmpID"])
                   .Union(BListItem.AsEnumerable()
                                   .Select(r => r.FieldValues["EmpID"]));

if (iPs.Count() > 0)
{
    List<ListItem> sample = (from row in AListItem.AsEnumerable()
                             join id in iPs
                             on row.FieldValues["EmpID"] equals id
                             select row).ToList();
}

But i need result in datatable in order to bind to repeater control. How can I convert List<ListItem> to datatable?

Abbas
  • 14,186
  • 6
  • 41
  • 72
user234
  • 120
  • 1
  • 10

2 Answers2

1

As mentioned in my comment, use sample as the datasource for the Repeater control.

This SO link provides detailed information on how to achieve this:

binding-a-generic-list-to-a-repeater-asp-net

The overview is this:

// Here's your object that you'll create a list of
private class Products
{
    public string ProductName { get; set; }
    public string ProductDescription { get; set; }
    public string ProductPrice { get; set; }
}

// Here you pass in the List of Products
private void BindItemsInCart(List<Products> ListOfSelectedProducts)
{   
    // The the LIST as the DataSource
    this.rptItemsInCart.DataSource = ListOfSelectedProducts;

    // Then bind the repeater
    // The public properties become the columns of your repeater
    this.rptItemsInCart.DataBind();
}

ASPX code:

<asp:Repeater ID="rptItemsInCart" runat="server">
  <HeaderTemplate>
    <table>
      <thead>
        <tr>
            <th>Product Name</th>
            <th>Product Description</th>
            <th>Product Price</th>
        </tr>
      </thead>
      <tbody>
  </HeaderTemplate>
  <ItemTemplate>
    <tr>
      <td><%# Eval("ProductName") %></td>
      <td><%# Eval("ProductDescription")%></td>
      <td><%# Eval("ProductPrice")%></td>
    </tr>
  </ItemTemplate>
  <FooterTemplate>
    </tbody>
    </table>
  </FooterTemplate>
</asp:Repeater>
Community
  • 1
  • 1
Ric
  • 12,855
  • 3
  • 30
  • 36
  • Well I didn't read the mysql tag so quickly got rid of it as the syntax is sql server! :) – Ric Dec 04 '13 at 16:09
0

I agree with Ric: Maybe it's better to bind the List.

But if you really need to convert to a datatable, check these links:

How to convert a List into DataTable

http://www.c-sharpcorner.com/UploadFile/1a81c5/list-to-datatable-converter-using-C-Sharp/

Community
  • 1
  • 1
  • this.ipRepeater.DataSource = sample; this.ipRepeater.DataBind(); but it is not working – user234 Dec 04 '13 at 13:01
  • is there an error message? Also, see this [link](http://stackoverflow.com/questions/674204/binding-a-generic-list-to-a-repeater-asp-net) – Joao Franco Dec 04 '13 at 13:09