Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   e.dataItem with XML problem. (http://www.velocityreviews.com/forums/t714520-e-dataitem-with-xml-problem.html)

André Freitas 02-10-2010 11:43 AM

e.dataItem with XML problem.
 
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 02-10-2010 11:56 AM

Re: e.dataItem with XML problem.
 
> 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



Alexey Smirnov 02-10-2010 01:31 PM

Re: e.dataItem with XML problem.
 
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;


All times are GMT. The time now is 07:35 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.