e.dataItem with XML problem.

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?
 
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?

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
 
G

Guest

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;
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top