Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > e.dataItem with XML problem.

Reply
Thread Tools

e.dataItem with XML problem.

 
 
André Freitas
Guest
Posts: n/a
 
      02-10-2010
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?



 
Reply With Quote
 
 
 
 
André Freitas
Guest
Posts: n/a
 
      02-10-2010
> 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


 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      02-10-2010
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;
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Print XML parsing to JspWriter (out) Class org.xml.sax.helpers.NewInstance can not access a member of class javax.xml.parsers.SAXParser with modifiers "protected" Per Magnus L?vold Java 0 11-15-2004 02:27 PM
embedding xml in xml as non-xml :) Mark Van Orman XML 5 09-15-2004 05:57 AM
What XML technologies to learn first for "XML Processing" and "XML Mapping"? Bomb Diggy Java 0 07-28-2004 07:26 AM
Help on including one XML document within another XML document using XML Schemas Tony Prichard XML 0 12-12-2003 03:18 PM



Advertisments