e.dataItem with XML problem.

Discussion in 'ASP .Net' started by André Freitas, Feb 10, 2010.

  1. Im using:

    XDocument xDocument = XDocument.Load("somexml");
    var linq =
    from itens in
    xDocument.Root.Elements("channel").Elements("item").Take(10)
    select new
    {
    title = (string)itens.Element("title"),
    link = (string)itens.Element("link")
    };
    rptBlogFeed.DataSource = linq;
    rptBlogFeed.DataBind();


    I do need to handle the Repeater_ItemDataBound, and im doing:

    protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs
    e)
    {
    if (e.Item.ItemType == ListItemType.Item)
    {
    DataRow dataRow = (DataRow)e.Item.DataItem;
    HyperLink hyperLink = (HyperLink)e.Item.FindControl("hlkBlog");
    hyperLink.Text = dataRow["title"].ToString();
    hyperLink.NavigateUrl = dataRow["link"].ToString();

    //some other things, dont matter at all

    }
    }

    Off course, im getting a error (var types):

    impossible to convert
    <>f__AnonymousType0`2[System.String,System.String]' to
    'System.Data.DataRow'

    How can I do that?
    André Freitas, Feb 10, 2010
    #1
    1. Advertising

  2. > Im using:
    >
    > XDocument xDocument = XDocument.Load("somexml");
    > var linq =
    > from itens in
    > xDocument.Root.Elements("channel").Elements("item").Take(10)
    > select new
    > {
    > title = (string)itens.Element("title"),
    > link = (string)itens.Element("link")
    > };
    > rptBlogFeed.DataSource = linq;
    > rptBlogFeed.DataBind();
    >
    >
    > I do need to handle the Repeater_ItemDataBound, and im doing:
    >
    > protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs
    > e)
    > {
    > if (e.Item.ItemType == ListItemType.Item)
    > {
    > DataRow dataRow = (DataRow)e.Item.DataItem;
    > HyperLink hyperLink = (HyperLink)e.Item.FindControl("hlkBlog");
    > hyperLink.Text = dataRow["title"].ToString();
    > hyperLink.NavigateUrl = dataRow["link"].ToString();
    >
    > //some other things, dont matter at all
    >
    > }
    > }
    >
    > Off course, im getting a error (var types):
    >
    > impossible to convert
    > <>f__AnonymousType0`2[System.String,System.String]' to
    > 'System.Data.DataRow'
    >
    > How can I do that?


    A second after i sent the post i got an idea, can someone check it?

    if (e.Item.ItemType == ListItemType.Item)
    {
    string title = DataBinder.Eval(e.Item.DataItem, "title").ToString();
    string link = DataBinder.Eval(e.Item.DataItem, "link").ToString();
    HyperLink hyperLink = (HyperLink)e.Item.FindControl("hlkBlog");
    hyperLink.Text = title;
    hyperLink.NavigateUrl = link;

    // some stuff
    }

    Regards
    André Freitas, Feb 10, 2010
    #2
    1. Advertising

  3. On Feb 10, 12:43 pm, "André Freitas" <andrefreitas> wrote:
    > Im using:
    >
    > XDocument xDocument = XDocument.Load("somexml");
    > var linq =
    >     from itens in
    > xDocument.Root.Elements("channel").Elements("item").Take(10)
    >         select new
    >         {
    >             title = (string)itens.Element("title"),
    >             link = (string)itens.Element("link")
    >         };
    >     rptBlogFeed.DataSource = linq;
    >     rptBlogFeed.DataBind();
    >
    > I do need to handle the Repeater_ItemDataBound, and im doing:
    >
    > protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs
    > e)
    > {
    >     if (e.Item.ItemType == ListItemType.Item)
    >     {
    >         DataRow dataRow = (DataRow)e.Item.DataItem;
    >         HyperLink hyperLink = (HyperLink)e.Item.FindControl("hlkBlog");
    >         hyperLink.Text = dataRow["title"].ToString();
    >         hyperLink.NavigateUrl = dataRow["link"].ToString();
    >
    >         //some other things, dont matter at all
    >
    >     }
    >
    > }
    >
    > Off course, im getting a error (var types):
    >
    >     impossible to convert
    > <>f__AnonymousType0`2[System.String,System.String]'  to
    > 'System.Data.DataRow'
    >
    > How can I do that?


    I think you can do it like

    hyperLink.Text = ((Evaluation)e.Item.DataItem).Title;
    Alexey Smirnov, Feb 10, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henri
    Replies:
    0
    Views:
    584
    Henri
    Aug 3, 2004
  2. ibiza
    Replies:
    2
    Views:
    5,637
    ibiza
    Feb 1, 2006
  3. Jeff

    DataItem is NULL, problem

    Jeff, Oct 13, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    526
  4. OrlandoRocks

    Container.DataItem in ASCX problem

    OrlandoRocks, Jul 15, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    173
    OrlandoRocks
    Jul 15, 2003
  5. Chumley the Walrus

    Datalist and container.dataitem problem

    Chumley the Walrus, Aug 13, 2004, in forum: ASP .Net Web Controls
    Replies:
    6
    Views:
    218
    Chumley the Walrus
    Aug 17, 2004
Loading...

Share This Page