LINQ - how to assign linq query to repeator - Asked By chitra ganapathy on 19-Sep-11 04:57 AM

sir,
i used the following query, but it shows me the error. plz help wer i made a mistake
public void fixtures()
    {
      XElement fixture = null;
      try
      {
        fixture = XElement.Load("http://synd.cricbuzz.com/onmobile-togo/schedule-internal.xml");
      }
      catch
      {
      }
      if (fixture != null)
      {
        var fix = from futu in fixture.Descendants("togoText")
            select (new{
              tit = futu.Element("title").Value,
              par = futu.Element("p").Value
            });
        Repeater1.DataSource = fix;
        Repeater1.DataBind();
      }
    }
Reena Jain replied to chitra ganapathy on 19-Sep-11 05:38 AM
Hi,

here is the code I am using to bind the repeator

private void FetchData(int take, int pageSize)
{    
using (NorthwindDataContext dc = new NorthwindDataContext())
{
var query = from p in dc.Customers.OrderBy(o => o.ContactName).Take(take).Skip(pageSize)
select new
{
ID = p.CustomerID,
Name = p.ContactName,
Count = dc.Customers.Count()
};

          
PagedDataSource page = new PagedDataSource();
page.AllowCustomPaging = true;
page.AllowPaging = true;
page.DataSource = query;
page.PageSize = 10;
Repeater1.DataSource = page;
Repeater1.DataBind();   
}
}
Suchit shah replied to chitra ganapathy on 19-Sep-11 05:48 AM

XDocument booksXML = XDocument.Load(Server.MapPath(“books.xml”));

XNamespace ns = “http://example.books.com”;

var authors = from book in booksXML.Descendants(ns + “author”)

select new Author

{

FirstName = book.Element(ns + “first-name”).Value,

LastName = book.Element(ns + “last-name”).Value

};

If(Author != null)

{

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

}

 

Do it like this it will work