e.dataItem with XML problem.

  • Thread starter Thread starter André Freitas
  • Start date Start date
A

André Freitas

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?
 
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
 
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;
 
Back
Top